History

Make AVFilterLink store the pointers to the source and destination pads, rather than their index.

Originally committed as revision 25227 to svn://svn.ffmpeg.org/ffmpeg/trunk

Stefano Sabatini committed 16 years ago

Commit acc04901 parent b3dd5e52 files · +30 −32Browse files

Unified · Split

2 files
  1. libavfilter/avfilter.c +26 −28
  2. libavfilter/avfilter.h +4 −4
libavfilter/avfilter.c+26−28
@@ -42,10 +42,6 @@ const char *avfilter_license(void) · 41 unmodified lines
4242 return LICENSE_PREFIX FFMPEG_LICENSE + sizeof(LICENSE_PREFIX) - 1;
4343 }
4444
45−/** helper macros to get the in/out pad on the dst/src filter */
46−#define link_dpad(link) link->dst-> input_pads[link->dstpad]
47−#define link_spad(link) link->src->output_pads[link->srcpad]
48−
4945 AVFilterBufferRef *avfilter_ref_buffer(AVFilterBufferRef *ref, int pmask)
5046 {
5147 AVFilterBufferRef *ret = av_malloc(sizeof(AVFilterBufferRef));
@@ -116,8 +112,8 @@ int avfilter_link(AVFilterContext *src, unsigned srcpad, · 64 unmodified lines
116112
117113 link->src = src;
118114 link->dst = dst;
119− link->srcpad = srcpad;
120− link->dstpad = dstpad;
115+ link->srcpad = &src->output_pads[srcpad];
116+ link->dstpad = &dst->input_pads[dstpad];
121117 link->type = src->output_pads[srcpad].type;
122118 assert(PIX_FMT_NONE == -1 && SAMPLE_FMT_NONE == -1);
123119 link->format = -1;
@@ -128,20 +124,22 @@ int avfilter_link(AVFilterContext *src, unsigned srcpad, · 4 unmodified lines
128124 int avfilter_insert_filter(AVFilterLink *link, AVFilterContext *filt,
129125 unsigned in, unsigned out)
130126 {
127+ unsigned dstpad_idx = link->dstpad - link->dst->input_pads;
128+
131129 av_log(link->dst, AV_LOG_INFO, "auto-inserting filter '%s' "
132130 "between the filter '%s' and the filter '%s'\n",
133131 filt->name, link->src->name, link->dst->name);
134132
135− link->dst->inputs[link->dstpad] = NULL;
136− if (avfilter_link(filt, out, link->dst, link->dstpad)) {
133+ link->dst->inputs[dstpad_idx] = NULL;
134+ if (avfilter_link(filt, out, link->dst, dstpad_idx)) {
137135 /* failed to link output filter to new filter */
138− link->dst->inputs[link->dstpad] = link;
136+ link->dst->inputs[dstpad_idx] = link;
139137 return -1;
140138 }
141139
142140 /* re-hookup the link to the new destination filter we inserted */
143141 link->dst = filt;
144− link->dstpad = in;
142+ link->dstpad = &filt->input_pads[in];
145143 filt->inputs[in] = link;
146144
147145 /* if any information on supported media formats already exists on the
@@ -175,12 +173,12 @@ int avfilter_config_links(AVFilterContext *filter) · 27 unmodified lines
175173 if (avfilter_config_links(link->src))
176174 return -1;
177175
178− if (!(config_link = link_spad(link).config_props))
176+ if (!(config_link = link->srcpad->config_props))
179177 config_link = avfilter_default_config_output_link;
180178 if (config_link(link))
181179 return -1;
182180
183− if ((config_link = link_dpad(link).config_props))
181+ if ((config_link = link->dstpad->config_props))
184182 if (config_link(link))
185183 return -1;
186184
@@ -249,8 +247,8 @@ AVFilterBufferRef *avfilter_get_video_buffer(AVFilterLink *link, int perms, int · 62 unmodified lines
249247 FF_DPRINTF_START(NULL, get_video_buffer); ff_dprintf_link(NULL, link, 0);
250248 dprintf(NULL, " perms:%s w:%d h:%d\n", ff_get_ref_perms_string(buf, sizeof(buf), perms), w, h);
251249
252− if (link_dpad(link).get_video_buffer)
253− ret = link_dpad(link).get_video_buffer(link, perms, w, h);
250+ if (link->dstpad->get_video_buffer)
251+ ret = link->dstpad->get_video_buffer(link, perms, w, h);
254252
255253 if (!ret)
256254 ret = avfilter_default_get_video_buffer(link, perms, w, h);
@@ -269,8 +267,8 @@ AVFilterBufferRef *avfilter_get_audio_buffer(AVFilterLink *link, int perms, · 12 unmodified lines
269267 {
270268 AVFilterBufferRef *ret = NULL;
271269
272− if (link_dpad(link).get_audio_buffer)
273− ret = link_dpad(link).get_audio_buffer(link, perms, sample_fmt, size, channel_layout, planar);
270+ if (link->dstpad->get_audio_buffer)
271+ ret = link->dstpad->get_audio_buffer(link, perms, sample_fmt, size, channel_layout, planar);
274272
275273 if (!ret)
276274 ret = avfilter_default_get_audio_buffer(link, perms, sample_fmt, size, channel_layout, planar);
@@ -285,8 +283,8 @@ int avfilter_request_frame(AVFilterLink *link) · 8 unmodified lines
285283 {
286284 FF_DPRINTF_START(NULL, request_frame); ff_dprintf_link(NULL, link, 1);
287285
288− if (link_spad(link).request_frame)
289− return link_spad(link).request_frame(link);
286+ if (link->srcpad->request_frame)
287+ return link->srcpad->request_frame(link);
290288 else if (link->src->inputs[0])
291289 return avfilter_request_frame(link->src->inputs[0]);
292290 else return -1;
@@ -296,8 +294,8 @@ int avfilter_poll_frame(AVFilterLink *link) · 3 unmodified lines
296294 {
297295 int i, min = INT_MAX;
298296
299− if (link_spad(link).poll_frame)
300− return link_spad(link).poll_frame(link);
297+ if (link->srcpad->poll_frame)
298+ return link->srcpad->poll_frame(link);
301299
302300 for (i = 0; i < link->src->input_count; i++) {
303301 int val;
@@ -315,7 +313,7 @@ int avfilter_poll_frame(AVFilterLink *link) · 11 unmodified lines
315313 void avfilter_start_frame(AVFilterLink *link, AVFilterBufferRef *picref)
316314 {
317315 void (*start_frame)(AVFilterLink *, AVFilterBufferRef *);
318− AVFilterPad *dst = &link_dpad(link);
316+ AVFilterPad *dst = link->dstpad;
319317
320318 FF_DPRINTF_START(NULL, start_frame); ff_dprintf_link(NULL, link, 0); dprintf(NULL, " "); ff_dprintf_ref(NULL, picref, 1);
321319
@@ -328,7 +326,7 @@ void avfilter_start_frame(AVFilterLink *link, AVFilterBufferRef *picref) · 6 unmodified lines
328326 av_log(link->dst, AV_LOG_DEBUG,
329327 "frame copy needed (have perms %x, need %x, reject %x)\n",
330328 picref->perms,
331− link_dpad(link).min_perms, link_dpad(link).rej_perms);
329+ link->dstpad->min_perms, link->dstpad->rej_perms);
332330
333331 link->cur_buf = avfilter_get_video_buffer(link, dst->min_perms, link->w, link->h);
334332 link->src_buf = picref;
@@ -344,7 +342,7 @@ void avfilter_end_frame(AVFilterLink *link) · 9 unmodified lines
344342 {
345343 void (*end_frame)(AVFilterLink *);
346344
347− if (!(end_frame = link_dpad(link).end_frame))
345+ if (!(end_frame = link->dstpad->end_frame))
348346 end_frame = avfilter_default_end_frame;
349347
350348 end_frame(link);
@@ -393,7 +391,7 @@ void avfilter_draw_slice(AVFilterLink *link, int y, int h, int slice_dir) · 42 unmodified lines
393391 }
394392 }
395393
396− if (!(draw_slice = link_dpad(link).draw_slice))
394+ if (!(draw_slice = link->dstpad->draw_slice))
397395 draw_slice = avfilter_default_draw_slice;
398396 draw_slice(link, y, h, slice_dir);
399397 }
@@ -401,7 +399,7 @@ void avfilter_draw_slice(AVFilterLink *link, int y, int h, int slice_dir) · 1 unmodified line
401399 void avfilter_filter_samples(AVFilterLink *link, AVFilterBufferRef *samplesref)
402400 {
403401 void (*filter_samples)(AVFilterLink *, AVFilterBufferRef *);
404− AVFilterPad *dst = &link_dpad(link);
402+ AVFilterPad *dst = link->dstpad;
405403
406404 if (!(filter_samples = dst->filter_samples))
407405 filter_samples = avfilter_default_filter_samples;
@@ -412,7 +410,7 @@ void avfilter_filter_samples(AVFilterLink *link, AVFilterBufferRef *samplesref) · 4 unmodified lines
412410
413411 av_log(link->dst, AV_LOG_DEBUG,
414412 "Copying audio data in avfilter (have perms %x, need %x, reject %x)\n",
415− samplesref->perms, link_dpad(link).min_perms, link_dpad(link).rej_perms);
413+ samplesref->perms, link->dstpad->min_perms, link->dstpad->rej_perms);
416414
417415 link->cur_buf = avfilter_default_get_audio_buffer(link, dst->min_perms,
418416 samplesref->format,
@@ -534,7 +532,7 @@ void avfilter_destroy(AVFilterContext *filter) · 115 unmodified lines
534532 for (i = 0; i < filter->input_count; i++) {
535533 if ((link = filter->inputs[i])) {
536534 if (link->src)
537− link->src->outputs[link->srcpad] = NULL;
535+ link->src->outputs[link->srcpad - link->src->output_pads] = NULL;
538536 avfilter_formats_unref(&link->in_formats);
539537 avfilter_formats_unref(&link->out_formats);
540538 }
@@ -543,7 +541,7 @@ void avfilter_destroy(AVFilterContext *filter) · 2 unmodified lines
543541 for (i = 0; i < filter->output_count; i++) {
544542 if ((link = filter->outputs[i])) {
545543 if (link->dst)
546− link->dst->inputs[link->dstpad] = NULL;
544+ link->dst->inputs[link->dstpad - link->dst->input_pads] = NULL;
547545 avfilter_formats_unref(&link->in_formats);
548546 avfilter_formats_unref(&link->out_formats);
549547 }
libavfilter/avfilter.h+4−4
@@ -25,8 +25,8 @@ · 24 unmodified lines
2525 #include "libavutil/avutil.h"
2626
2727 #define LIBAVFILTER_VERSION_MAJOR 1
28−#define LIBAVFILTER_VERSION_MINOR 46
29−#define LIBAVFILTER_VERSION_MICRO 1
28+#define LIBAVFILTER_VERSION_MINOR 47
29+#define LIBAVFILTER_VERSION_MICRO 0
3030
3131 #define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \
3232 LIBAVFILTER_VERSION_MINOR, \
@@ -556,10 +556,10 @@ struct AVFilterContext { · 523 unmodified lines
556556 */
557557 struct AVFilterLink {
558558 AVFilterContext *src; ///< source filter
559− unsigned int srcpad; ///< index of the output pad on the source filter
559+ AVFilterPad *srcpad; ///< output pad on the source filter
560560
561561 AVFilterContext *dst; ///< dest filter
562− unsigned int dstpad; ///< index of the input pad on the dest filter
562+ AVFilterPad *dstpad; ///< input pad on the dest filter
563563
564564 /** stage of the initialization of the link properties (dimensions, etc) */
565565 enum {

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