History

lavfi: use min_perms and rej_perms for out pads.

There are several reasons for doing that: 1. It documents the code for the reader and helps find inconsistencies and bugs. 2. For rej_perms, it guarantees the change will be done even if the output reference can be created by several code paths. 3. It can be used to predict cases where a copy will, or will not happen and optimize buffer allocation (for example not request a rare direct-rendering buffer from a device sink if it will be copied anyway). Note that a filter is still allowed to manage the permissions on its own without using these fields.

Nicolas George committed 14 years ago

Commit 271ddb11 parent 67a804b3 files · +19 −3Browse files

Unified · Split

3 files
  1. libavfilter/audio.c +4 −0
  2. libavfilter/avfilter.h +9 −2
  3. libavfilter/video.c +6 −1
libavfilter/audio.c+4−0
@@ -159,6 +159,7 @@ static int default_filter_samples(AVFilterLink *link, · 158 unmodified lines
159159 int ff_filter_samples_framed(AVFilterLink *link, AVFilterBufferRef *samplesref)
160160 {
161161 int (*filter_samples)(AVFilterLink *, AVFilterBufferRef *);
162+ AVFilterPad *src = link->srcpad;
162163 AVFilterPad *dst = link->dstpad;
163164 int64_t pts;
164165 AVFilterBufferRef *buf_out;
@@ -169,6 +170,9 @@ int ff_filter_samples_framed(AVFilterLink *link, AVFilterBufferRef *samplesref) · 4 unmodified lines
169170 if (!(filter_samples = dst->filter_samples))
170171 filter_samples = default_filter_samples;
171172
173+ av_assert1((samplesref->perms & src->min_perms) == src->min_perms);
174+ samplesref->perms &= ~ src->rej_perms;
175+
172176 /* prepare to copy the samples if the buffer has insufficient permissions */
173177 if ((dst->min_perms & samplesref->perms) != dst->min_perms ||
174178 dst->rej_perms & samplesref->perms) {
libavfilter/avfilter.h+9−2
@@ -240,22 +240,29 @@ struct AVFilterPad { · 239 unmodified lines
240240 enum AVMediaType type;
241241
242242 /**
243+ * Input pads:
243244 * Minimum required permissions on incoming buffers. Any buffer with
244245 * insufficient permissions will be automatically copied by the filter
245246 * system to a new buffer which provides the needed access permissions.
246247 *
247− * Input pads only.
248+ * Output pads:
249+ * Guaranteed permissions on outgoing buffers. Any buffer pushed on the
250+ * link must have at least these permissions; this fact is checked by
251+ * asserts. It can be used to optimize buffer allocation.
248252 */
249253 int min_perms;
250254
251255 /**
256+ * Input pads:
252257 * Permissions which are not accepted on incoming buffers. Any buffer
253258 * which has any of these permissions set will be automatically copied
254259 * by the filter system to a new buffer which does not have those
255260 * permissions. This can be used to easily disallow buffers with
256261 * AV_PERM_REUSE.
257262 *
258− * Input pads only.
263+ * Output pads:
264+ * Permissions which are automatically removed on outgoing buffers. It
265+ * can be used to optimize buffer allocation.
259266 */
260267 int rej_perms;
261268
libavfilter/video.c+6−1
@@ -232,8 +232,9 @@ static void clear_link(AVFilterLink *link) · 231 unmodified lines
232232 int ff_start_frame(AVFilterLink *link, AVFilterBufferRef *picref)
233233 {
234234 int (*start_frame)(AVFilterLink *, AVFilterBufferRef *);
235+ AVFilterPad *src = link->srcpad;
235236 AVFilterPad *dst = link->dstpad;
236− int ret, perms = picref->perms;
237+ int ret, perms;
237238 AVFilterCommand *cmd= link->dst->command_queue;
238239 int64_t pts;
239240
@@ -242,6 +243,10 @@ int ff_start_frame(AVFilterLink *link, AVFilterBufferRef *picref) · 2 unmodified lines
242243 if (!(start_frame = dst->start_frame))
243244 start_frame = default_start_frame;
244245
246+ av_assert1((picref->perms & src->min_perms) == src->min_perms);
247+ picref->perms &= ~ src->rej_perms;
248+ perms = picref->perms;
249+
245250 if (picref->linesize[0] < 0)
246251 perms |= AV_PERM_NEG_LINESIZES;
247252 /* prepare to copy the picture if it has insufficient permissions */

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