History

lavfi: add helpers to consume frames from link FIFOs.

Nicolas George committed 9 years ago

Commit d360ddf1 parent 2e5af442 files · +94 −0Browse files

Unified · Split

2 files
  1. libavfilter/avfilter.c +52 −0
  2. libavfilter/filters.h +42 −0
libavfilter/avfilter.c+52−0
@@ -1501,6 +1501,58 @@ int ff_inlink_acknowledge_status(AVFilterLink *link, int *rstatus, int64_t *rpts · 1500 unmodified lines
1501 return 1;1501 return 1;
1502}1502}
1503 1503
1504int ff_inlink_check_available_frame(AVFilterLink *link)
1505{
1506 return ff_framequeue_queued_frames(&link->fifo) > 0;
1507}
1508
1509int ff_inlink_check_available_samples(AVFilterLink *link, unsigned min)
1510{
1511 uint64_t samples = ff_framequeue_queued_samples(&link->fifo);
1512 av_assert1(min);
1513 return samples >= min || (link->status_in && samples);
1514}
1515
1516static void consume_update(AVFilterLink *link, const AVFrame *frame)
1517{
1518 ff_inlink_process_commands(link, frame);
1519 link->dst->is_disabled = !ff_inlink_evaluate_timeline_at_frame(link, frame);
1520 link->frame_count_out++;
1521}
1522
1523int ff_inlink_consume_frame(AVFilterLink *link, AVFrame **rframe)
1524{
1525 AVFrame *frame;
1526
1527 *rframe = NULL;
1528 if (!ff_inlink_check_available_frame(link))
1529 return 0;
1530 frame = ff_framequeue_take(&link->fifo);
1531 consume_update(link, frame);
1532 *rframe = frame;
1533 return 1;
1534}
1535
1536int ff_inlink_consume_samples(AVFilterLink *link, unsigned min, unsigned max,
1537 AVFrame **rframe)
1538{
1539 AVFrame *frame;
1540 int ret;
1541
1542 av_assert1(min);
1543 *rframe = NULL;
1544 if (!ff_inlink_check_available_samples(link, min))
1545 return 0;
1546 if (link->status_in)
1547 min = FFMIN(min, ff_framequeue_queued_samples(&link->fifo));
1548 ret = take_samples(link, min, link->max_samples, &frame);
1549 if (ret < 0)
1550 return ret;
1551 consume_update(link, frame);
1552 *rframe = frame;
1553 return 1;
1554}
1555
1504int ff_inlink_make_frame_writable(AVFilterLink *link, AVFrame **rframe)1556int ff_inlink_make_frame_writable(AVFilterLink *link, AVFrame **rframe)
1505{1557{
1506 AVFrame *frame = *rframe;1558 AVFrame *frame = *rframe;
libavfilter/filters.h+42−0
@@ -54,6 +54,48 @@ int ff_inlink_process_commands(AVFilterLink *link, const AVFrame *frame); · 53 unmodified lines
54 */54 */
55int ff_inlink_evaluate_timeline_at_frame(AVFilterLink *link, const AVFrame *frame);55int ff_inlink_evaluate_timeline_at_frame(AVFilterLink *link, const AVFrame *frame);
56 56
57/**
58 * Test if a frame is available on the link.
59 * @return >0 if a frame is available
60 */
61int ff_inlink_check_available_frame(AVFilterLink *link);
62
63/**
64 * Test if enough samples are available on the link.
65 * @return >0 if enough samples are available
66 * @note on EOF and error, min becomes 1
67 */
68int ff_inlink_check_available_samples(AVFilterLink *link, unsigned min);
69
70/**
71 * Take a frame from the link's FIFO and update the link's stats.
72 *
73 * If ff_inlink_check_available_frame() was previously called, the
74 * preferred way of expressing it is "av_assert1(ret);" immediately after
75 * ff_inlink_consume_frame(). Negative error codes must still be checked.
76 *
77 * @note May trigger process_command() and/or update is_disabled.
78 * @return >0 if a frame is available,
79 * 0 and set rframe to NULL if no frame available,
80 * or AVERROR code
81 */
82int ff_inlink_consume_frame(AVFilterLink *link, AVFrame **rframe);
83
84/**
85 * Take samples from the link's FIFO and update the link's stats.
86 *
87 * If ff_inlink_check_available_samples() was previously called, the
88 * preferred way of expressing it is "av_assert1(ret);" immediately after
89 * ff_inlink_consume_samples(). Negative error codes must still be checked.
90 *
91 * @note May trigger process_command() and/or update is_disabled.
92 * @return >0 if a frame is available,
93 * 0 and set rframe to NULL if no frame available,
94 * or AVERROR code
95 */
96int ff_inlink_consume_samples(AVFilterLink *link, unsigned min, unsigned max,
97 AVFrame **rframe);
98
57/**99/**
58 * Make sure a frame is writable.100 * Make sure a frame is writable.
59 * This is similar to av_frame_make_writable() except it uses the link's101 * This is similar to av_frame_make_writable() except it uses the link's

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t