static int request_frame(AVFilterLink *outlink) { AVFilterContext *ctx = outlink->src; SelectContext *select = ctx->priv; AVFilterLink *inlink = outlink->src->inputs[0]; select->select = 0; if (av_fifo_size(select->pending_frames)) { AVFilterBufferRef *picref; av_fifo_generic_read(select->pending_frames, &picref, sizeof(picref), NULL); avfilter_start_frame(outlink, avfilter_ref_buffer(picref, ~0)); avfilter_draw_slice(outlink, 0, outlink->h, 1); avfilter_end_frame(outlink); avfilter_unref_buffer(picref); return 0; } while (!select->select) { int ret = avfilter_request_frame(inlink); if (ret < 0) return ret; } return 0; }
static int request_frame(AVFilterLink *outlink) { FifoContext *fifo = outlink->src->priv; BufPic *tmp; int ret; if (!fifo->root.next) { if ((ret = avfilter_request_frame(outlink->src->inputs[0]) < 0)) return ret; } /* by doing this, we give ownership of the reference to the next filter, * so we don't have to worry about dereferencing it ourselves. */ avfilter_start_frame(outlink, fifo->root.next->picref); avfilter_draw_slice (outlink, 0, outlink->h, 1); avfilter_end_frame (outlink); if (fifo->last == fifo->root.next) fifo->last = &fifo->root; tmp = fifo->root.next->next; av_free(fifo->root.next); fifo->root.next = tmp; return 0; }
int get_filtered_video_frame(AVFilterContext *ctx, AVFrame *frame, AVFilterBufferRef **picref_ptr, AVRational *tb) { int ret; AVFilterBufferRef *picref; if ((ret = avfilter_request_frame(ctx->inputs[0])) < 0) return ret; if (!(picref = ctx->inputs[0]->cur_buf)) return AVERROR(ENOENT); *picref_ptr = picref; ctx->inputs[0]->cur_buf = NULL; *tb = ctx->inputs[0]->time_base; memcpy(frame->data, picref->data, sizeof(frame->data)); memcpy(frame->linesize, picref->linesize, sizeof(frame->linesize)); frame->pkt_pos = picref->pos; frame->interlaced_frame = picref->video->interlaced; frame->top_field_first = picref->video->top_field_first; frame->key_frame = picref->video->key_frame; frame->pict_type = picref->video->pict_type; frame->sample_aspect_ratio = picref->video->sample_aspect_ratio; return 1; }
static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts) { AVFilterBufferRef *buf; mp_image_t *cmpi = NULL; if (!(mpi->flags & MP_IMGFLAG_DIRECT)) { cmpi = vf_get_image(vf, mpi->imgfmt, MP_IMGTYPE_TEMP, MP_IMGFLAG_PREFER_ALIGNED_STRIDE, mpi->w, mpi->h); copy_mpi(cmpi, mpi); buf = cmpi->priv; } else { buf = mpi->priv; } buf->video->key_frame = mpi->pict_type == 1; buf->video->pict_type = mpi->pict_type; /* seems to be the same code */ buf->video->interlaced = !!(mpi->fields & MP_IMGFIELD_INTERLACED); buf->video->top_field_first = !!(mpi->fields & MP_IMGFIELD_TOP_FIRST); vf->priv->in_buf = buf; if (pts != MP_NOPTS_VALUE) buf->pts = pts * AV_TIME_BASE; while (avfilter_poll_frame(vf->priv->out->inputs[0])) { if (avfilter_request_frame(vf->priv->out->inputs[0])) break; } return 1; }
static int request_frame(AVFilterLink *outlink) { AVFilterContext *ctx = outlink->src; ResampleContext *s = ctx->priv; int ret = avfilter_request_frame(ctx->inputs[0]); /* flush the lavr delay buffer */ if (ret == AVERROR_EOF && s->avr) { AVFilterBufferRef *buf; int nb_samples = av_rescale_rnd(avresample_get_delay(s->avr), outlink->sample_rate, ctx->inputs[0]->sample_rate, AV_ROUND_UP); if (!nb_samples) return ret; buf = ff_get_audio_buffer(outlink, AV_PERM_WRITE, nb_samples); if (!buf) return AVERROR(ENOMEM); ret = avresample_convert(s->avr, (void**)buf->extended_data, buf->linesize[0], nb_samples, NULL, 0, 0); if (ret <= 0) { avfilter_unref_buffer(buf); return (ret == 0) ? AVERROR_EOF : ret; } buf->pts = s->next_pts; ff_filter_samples(outlink, buf); return 0; } return ret; }
int avfilter_request_frame(AVFilterLink *link) { FF_DPRINTF_START(NULL, request_frame); ff_dlog_link(NULL, link, 1); if (link->srcpad->request_frame) return link->srcpad->request_frame(link); else if (link->src->inputs[0]) return avfilter_request_frame(link->src->inputs[0]); else return -1; }
static int request_frame(AVFilterLink *link) { ThumbContext *thumb = link->src->priv; /* loop until a frame thumbnail is available (when a frame is queued, * thumb->n is reset to zero) */ do { int ret = avfilter_request_frame(link->src->inputs[0]); if (ret < 0) return ret; } while (thumb->n); return 0; }
int avfilter_graph_request_oldest(AVFilterGraph *graph) { while (graph->sink_links_count) { AVFilterLink *oldest = graph->sink_links[0]; int r = avfilter_request_frame(oldest); if (r != AVERROR_EOF) return r; /* EOF: remove the link from the heap */ if (oldest->age_index < --graph->sink_links_count) heap_bubble_down(graph, graph->sink_links[graph->sink_links_count], oldest->age_index); oldest->age_index = -1; } return AVERROR_EOF; }
static int poll_frame(AVFilterLink *link) { FPSContext *fps = link->src->priv; if (fps->has_frame) return 1; if(avfilter_poll_frame(link->src->inputs[0]) && avfilter_request_frame(link->src->inputs[0])) { fps->videoend = 1; return 1; } fps->has_frame = !!(fps->pic && fps->pic->pts >= fps->pts); return fps->has_frame; }
int av_asink_abuffer_get_audio_buffer_ref(AVFilterContext *abuffersink, AVFilterBufferRef **samplesref, int av_unused flags) { int ret; AVFilterLink * const inlink = abuffersink->inputs[0]; if ((ret = avfilter_request_frame(inlink))) return ret; if (!inlink->cur_buf) return AVERROR(EINVAL); *samplesref = inlink->cur_buf; inlink->cur_buf = NULL; return 0; }
static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *inpicref) { AVFilterBufferRef *outpicref = avfilter_ref_buffer(inpicref, ~0); AVFilterContext *ctx = inlink->dst; OverlayContext *over = ctx->priv; inlink->dst->outputs[0]->out_buf = outpicref; if (!over->overpicref || over->overpicref->pts < outpicref->pts) { AVFilterBufferRef *old = over->overpicref; over->overpicref = NULL; avfilter_request_frame(ctx->inputs[OVERLAY]); if (over->overpicref) { if (old) avfilter_unref_buffer(old); } else over->overpicref = old; } avfilter_start_frame(inlink->dst->outputs[0], outpicref); }
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 = avfilter_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 = avfilter_request_frame(inlink); if (ret < 0) break; } select->cache_frames = 0; } return av_fifo_size(select->pending_frames)/sizeof(AVFilterBufferRef *); }
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; }
int av_vsink_buffer_get_video_buffer_ref(AVFilterContext *ctx, AVFilterBufferRef **picref, int flags) { BufferSinkContext *buf = ctx->priv; AVFilterLink *inlink = ctx->inputs[0]; int ret; *picref = NULL; /* no picref available, fetch it from the filterchain */ if (!buf->picref) { if ((ret = avfilter_request_frame(inlink)) < 0) return ret; } if (!buf->picref) return AVERROR(EINVAL); *picref = buf->picref; if (!(flags & AV_VSINK_BUF_FLAG_PEEK)) buf->picref = NULL; return 0; }
int av_buffersink_get_buffer_ref(AVFilterContext *ctx, AVFilterBufferRef **bufref, int flags) { BufferSinkContext *buf = ctx->priv; AVFilterLink *inlink = ctx->inputs[0]; int ret; *bufref = NULL; /* no picref available, fetch it from the filterchain */ if (!av_fifo_size(buf->fifo)) { if ((ret = avfilter_request_frame(inlink)) < 0) return ret; } if (!av_fifo_size(buf->fifo)) return AVERROR(EINVAL); if (flags & AV_BUFFERSINK_FLAG_PEEK) *bufref = *((AVFilterBufferRef **)av_fifo_peek2(buf->fifo, 0)); else av_fifo_generic_read(buf->fifo, bufref, sizeof(*bufref), NULL); return 0; }
static int request_frame(AVFilterLink *link) { FPSContext *fps = link->src->priv; if (fps->videoend) return -1; if (!fps->has_frame) // support for filtering without poll_frame usage while(!fps->pic || fps->pic->pts < fps->pts) if(avfilter_request_frame(link->src->inputs[0])) return -1; fps->has_frame=0; avfilter_start_frame(link, avfilter_ref_pic(fps->pic, ~AV_PERM_WRITE)); avfilter_draw_slice (link, 0, fps->pic->h, 1); avfilter_end_frame (link); avfilter_unref_pic(fps->pic); fps->pic = NULL; fps->pts += fps->timebase; return 0; }
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 avfilter_poll_frame(ctx->inputs[0]); } if (!av_fifo_size(sink->fifo) && (ret = avfilter_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; }