int attribute_align_arg av_buffersink_poll_frame(AVFilterContext *ctx) { BufferSinkContext *buf = ctx->priv; AVFilterLink *inlink = ctx->inputs[0]; av_assert0( !strcmp(ctx->filter->name, "buffersink") || !strcmp(ctx->filter->name, "abuffersink") || !strcmp(ctx->filter->name, "ffbuffersink") || !strcmp(ctx->filter->name, "ffabuffersink")); return av_fifo_size(buf->fifo)/sizeof(AVFilterBufferRef *) + ff_poll_frame(inlink); }
static int compat_read(AVFilterContext *ctx, AVFilterBufferRef **pbuf, int nb_samples) { AVFilterBufferRef *buf; AVFrame *frame; int ret; if (!pbuf) return ff_poll_frame(ctx->inputs[0]); frame = av_frame_alloc(); if (!frame) return AVERROR(ENOMEM); if (!nb_samples) ret = av_buffersink_get_frame(ctx, frame); else ret = av_buffersink_get_samples(ctx, frame, nb_samples); if (ret < 0) goto fail; if (ctx->inputs[0]->type == AVMEDIA_TYPE_VIDEO) { buf = avfilter_get_video_buffer_ref_from_arrays(frame->data, frame->linesize, AV_PERM_READ, frame->width, frame->height, frame->format); } else { buf = avfilter_get_audio_buffer_ref_from_arrays(frame->extended_data, frame->linesize[0], AV_PERM_READ, frame->nb_samples, frame->format, frame->channel_layout); } if (!buf) { ret = AVERROR(ENOMEM); goto fail; } avfilter_copy_frame_props(buf, frame); buf->buf->priv = frame; buf->buf->free = compat_free_buffer; *pbuf = buf; return 0; fail: av_frame_free(&frame); return ret; }
int ff_poll_frame(AVFilterLink *link) { int i, min = INT_MAX; if (link->srcpad->poll_frame) return link->srcpad->poll_frame(link); for (i = 0; i < link->src->nb_inputs; i++) { int val; if (!link->src->inputs[i]) return AVERROR(EINVAL); val = ff_poll_frame(link->src->inputs[i]); min = FFMIN(min, val); } return min; }
int ff_poll_frame(AVFilterLink *link) { int i, min = INT_MAX; if (link->srcpad->poll_frame) return link->srcpad->poll_frame(link); for (i = 0; i < link->src->input_count; i++) { int val; if (!link->src->inputs[i]) return -1; val = ff_poll_frame(link->src->inputs[i]); min = FFMIN(min, val); } return min; }
int ff_buffersink_read_compat(AVFilterContext *ctx, AVFilterBufferRef **buf) { BufferSinkContext *s = ctx->priv; AVFilterLink *link = ctx->inputs[0]; int ret; if (!buf) return ff_poll_frame(ctx->inputs[0]); if ((ret = ff_request_frame(link)) < 0) return ret; if (!s->cur_buf) return AVERROR(EINVAL); *buf = s->cur_buf; s->cur_buf = NULL; return 0; }
static int poll_frame(AVFilterLink *link) { ThumbContext *thumb = link->src->priv; AVFilterLink *inlink = link->src->inputs[0]; int ret, available_frames = ff_poll_frame(inlink); /* If the input link is not able to provide any frame, we can't do anything * at the moment and thus have zero thumbnail available. */ if (!available_frames) return 0; /* Since at least one frame is available and the next frame will allow us * to compute a thumbnail, we can return 1 frame. */ if (thumb->n == thumb->n_frames - 1) return 1; /* we have some frame(s) available in the input link, but not yet enough to * output a thumbnail, so we request more */ ret = avfilter_request_frame(inlink); return ret < 0 ? ret : 0; }
static int poll_frame(AVFilterLink *outlink) { SelectContext *select = outlink->src->priv; AVFilterLink *inlink = outlink->src->inputs[0]; int count, ret; if (!av_fifo_size(select->pending_frames)) { if ((count = ff_poll_frame(inlink)) <= 0) return count; /* request frame from input, and apply select condition to it */ select->cache_frames = 1; while (count-- && av_fifo_space(select->pending_frames)) { ret = ff_request_frame(inlink); if (ret < 0) break; } select->cache_frames = 0; } return av_fifo_size(select->pending_frames)/sizeof(AVFrame*); }
int av_buffersink_read(AVFilterContext *ctx, AVFilterBufferRef **buf) { BufferSinkContext *sink = ctx->priv; AVFilterLink *link = ctx->inputs[0]; int ret; if (!buf) { if (av_fifo_size(sink->fifo)) return av_fifo_size(sink->fifo)/sizeof(*buf); else return ff_poll_frame(ctx->inputs[0]); } if (!av_fifo_size(sink->fifo) && (ret = ff_request_frame(link)) < 0) return ret; if (!av_fifo_size(sink->fifo)) return AVERROR(EINVAL); av_fifo_generic_read(sink->fifo, buf, sizeof(*buf), NULL); return 0; }
int avfilter_poll_frame(AVFilterLink *link) { return ff_poll_frame(link); }