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

Showing the changes to libavfilter/avfilter.c (1 of 2 files). Show all

Unified · Split

libavfilter/avfilter.c+26−28
@@ -42,10 +42,6 @@ const char *avfilter_license(void) · 41 unmodified lines
42 return LICENSE_PREFIX FFMPEG_LICENSE + sizeof(LICENSE_PREFIX) - 1;42 return LICENSE_PREFIX FFMPEG_LICENSE + sizeof(LICENSE_PREFIX) - 1;
43}43}
44 44
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
49AVFilterBufferRef *avfilter_ref_buffer(AVFilterBufferRef *ref, int pmask)45AVFilterBufferRef *avfilter_ref_buffer(AVFilterBufferRef *ref, int pmask)
50{46{
51 AVFilterBufferRef *ret = av_malloc(sizeof(AVFilterBufferRef));47 AVFilterBufferRef *ret = av_malloc(sizeof(AVFilterBufferRef));
@@ -116,8 +112,8 @@ int avfilter_link(AVFilterContext *src, unsigned srcpad, · 64 unmodified lines
116 112
117 link->src = src;113 link->src = src;
118 link->dst = dst;114 link->dst = dst;
119 link->srcpad = srcpad;115 link->srcpad = &src->output_pads[srcpad];
120 link->dstpad = dstpad;116 link->dstpad = &dst->input_pads[dstpad];
121 link->type = src->output_pads[srcpad].type;117 link->type = src->output_pads[srcpad].type;
122 assert(PIX_FMT_NONE == -1 && SAMPLE_FMT_NONE == -1);118 assert(PIX_FMT_NONE == -1 && SAMPLE_FMT_NONE == -1);
123 link->format = -1;119 link->format = -1;
@@ -128,20 +124,22 @@ int avfilter_link(AVFilterContext *src, unsigned srcpad, · 4 unmodified lines
128int avfilter_insert_filter(AVFilterLink *link, AVFilterContext *filt,124int avfilter_insert_filter(AVFilterLink *link, AVFilterContext *filt,
129 unsigned in, unsigned out)125 unsigned in, unsigned out)
130{126{
127 unsigned dstpad_idx = link->dstpad - link->dst->input_pads;
128
131 av_log(link->dst, AV_LOG_INFO, "auto-inserting filter '%s' "129 av_log(link->dst, AV_LOG_INFO, "auto-inserting filter '%s' "
132 "between the filter '%s' and the filter '%s'\n",130 "between the filter '%s' and the filter '%s'\n",
133 filt->name, link->src->name, link->dst->name);131 filt->name, link->src->name, link->dst->name);
134 132
135 link->dst->inputs[link->dstpad] = NULL;133 link->dst->inputs[dstpad_idx] = NULL;
136 if (avfilter_link(filt, out, link->dst, link->dstpad)) {134 if (avfilter_link(filt, out, link->dst, dstpad_idx)) {
137 /* failed to link output filter to new filter */135 /* failed to link output filter to new filter */
138 link->dst->inputs[link->dstpad] = link;136 link->dst->inputs[dstpad_idx] = link;
139 return -1;137 return -1;
140 }138 }
141 139
142 /* re-hookup the link to the new destination filter we inserted */140 /* re-hookup the link to the new destination filter we inserted */
143 link->dst = filt;141 link->dst = filt;
144 link->dstpad = in;142 link->dstpad = &filt->input_pads[in];
145 filt->inputs[in] = link;143 filt->inputs[in] = link;
146 144
147 /* if any information on supported media formats already exists on the145 /* if any information on supported media formats already exists on the
@@ -175,12 +173,12 @@ int avfilter_config_links(AVFilterContext *filter) · 27 unmodified lines
175 if (avfilter_config_links(link->src))173 if (avfilter_config_links(link->src))
176 return -1;174 return -1;
177 175
178 if (!(config_link = link_spad(link).config_props))176 if (!(config_link = link->srcpad->config_props))
179 config_link = avfilter_default_config_output_link;177 config_link = avfilter_default_config_output_link;
180 if (config_link(link))178 if (config_link(link))
181 return -1;179 return -1;
182 180
183 if ((config_link = link_dpad(link).config_props))181 if ((config_link = link->dstpad->config_props))
184 if (config_link(link))182 if (config_link(link))
185 return -1;183 return -1;
186 184
@@ -249,8 +247,8 @@ AVFilterBufferRef *avfilter_get_video_buffer(AVFilterLink *link, int perms, int · 62 unmodified lines
249 FF_DPRINTF_START(NULL, get_video_buffer); ff_dprintf_link(NULL, link, 0);247 FF_DPRINTF_START(NULL, get_video_buffer); ff_dprintf_link(NULL, link, 0);
250 dprintf(NULL, " perms:%s w:%d h:%d\n", ff_get_ref_perms_string(buf, sizeof(buf), perms), w, h);248 dprintf(NULL, " perms:%s w:%d h:%d\n", ff_get_ref_perms_string(buf, sizeof(buf), perms), w, h);
251 249
252 if (link_dpad(link).get_video_buffer)250 if (link->dstpad->get_video_buffer)
253 ret = link_dpad(link).get_video_buffer(link, perms, w, h);251 ret = link->dstpad->get_video_buffer(link, perms, w, h);
254 252
255 if (!ret)253 if (!ret)
256 ret = avfilter_default_get_video_buffer(link, perms, w, h);254 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
269{267{
270 AVFilterBufferRef *ret = NULL;268 AVFilterBufferRef *ret = NULL;
271 269
272 if (link_dpad(link).get_audio_buffer)270 if (link->dstpad->get_audio_buffer)
273 ret = link_dpad(link).get_audio_buffer(link, perms, sample_fmt, size, channel_layout, planar);271 ret = link->dstpad->get_audio_buffer(link, perms, sample_fmt, size, channel_layout, planar);
274 272
275 if (!ret)273 if (!ret)
276 ret = avfilter_default_get_audio_buffer(link, perms, sample_fmt, size, channel_layout, planar);274 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
285{283{
286 FF_DPRINTF_START(NULL, request_frame); ff_dprintf_link(NULL, link, 1);284 FF_DPRINTF_START(NULL, request_frame); ff_dprintf_link(NULL, link, 1);
287 285
288 if (link_spad(link).request_frame)286 if (link->srcpad->request_frame)
289 return link_spad(link).request_frame(link);287 return link->srcpad->request_frame(link);
290 else if (link->src->inputs[0])288 else if (link->src->inputs[0])
291 return avfilter_request_frame(link->src->inputs[0]);289 return avfilter_request_frame(link->src->inputs[0]);
292 else return -1;290 else return -1;
@@ -296,8 +294,8 @@ int avfilter_poll_frame(AVFilterLink *link) · 3 unmodified lines
296{294{
297 int i, min = INT_MAX;295 int i, min = INT_MAX;
298 296
299 if (link_spad(link).poll_frame)297 if (link->srcpad->poll_frame)
300 return link_spad(link).poll_frame(link);298 return link->srcpad->poll_frame(link);
301 299
302 for (i = 0; i < link->src->input_count; i++) {300 for (i = 0; i < link->src->input_count; i++) {
303 int val;301 int val;
@@ -315,7 +313,7 @@ int avfilter_poll_frame(AVFilterLink *link) · 11 unmodified lines
315void avfilter_start_frame(AVFilterLink *link, AVFilterBufferRef *picref)313void avfilter_start_frame(AVFilterLink *link, AVFilterBufferRef *picref)
316{314{
317 void (*start_frame)(AVFilterLink *, AVFilterBufferRef *);315 void (*start_frame)(AVFilterLink *, AVFilterBufferRef *);
318 AVFilterPad *dst = &link_dpad(link);316 AVFilterPad *dst = link->dstpad;
319 317
320 FF_DPRINTF_START(NULL, start_frame); ff_dprintf_link(NULL, link, 0); dprintf(NULL, " "); ff_dprintf_ref(NULL, picref, 1);318 FF_DPRINTF_START(NULL, start_frame); ff_dprintf_link(NULL, link, 0); dprintf(NULL, " "); ff_dprintf_ref(NULL, picref, 1);
321 319
@@ -328,7 +326,7 @@ void avfilter_start_frame(AVFilterLink *link, AVFilterBufferRef *picref) · 6 unmodified lines
328 av_log(link->dst, AV_LOG_DEBUG,326 av_log(link->dst, AV_LOG_DEBUG,
329 "frame copy needed (have perms %x, need %x, reject %x)\n",327 "frame copy needed (have perms %x, need %x, reject %x)\n",
330 picref->perms,328 picref->perms,
331 link_dpad(link).min_perms, link_dpad(link).rej_perms);329 link->dstpad->min_perms, link->dstpad->rej_perms);
332 330
333 link->cur_buf = avfilter_get_video_buffer(link, dst->min_perms, link->w, link->h);331 link->cur_buf = avfilter_get_video_buffer(link, dst->min_perms, link->w, link->h);
334 link->src_buf = picref;332 link->src_buf = picref;
@@ -344,7 +342,7 @@ void avfilter_end_frame(AVFilterLink *link) · 9 unmodified lines
344{342{
345 void (*end_frame)(AVFilterLink *);343 void (*end_frame)(AVFilterLink *);
346 344
347 if (!(end_frame = link_dpad(link).end_frame))345 if (!(end_frame = link->dstpad->end_frame))
348 end_frame = avfilter_default_end_frame;346 end_frame = avfilter_default_end_frame;
349 347
350 end_frame(link);348 end_frame(link);
@@ -393,7 +391,7 @@ void avfilter_draw_slice(AVFilterLink *link, int y, int h, int slice_dir) · 42 unmodified lines
393 }391 }
394 }392 }
395 393
396 if (!(draw_slice = link_dpad(link).draw_slice))394 if (!(draw_slice = link->dstpad->draw_slice))
397 draw_slice = avfilter_default_draw_slice;395 draw_slice = avfilter_default_draw_slice;
398 draw_slice(link, y, h, slice_dir);396 draw_slice(link, y, h, slice_dir);
399}397}
@@ -401,7 +399,7 @@ void avfilter_draw_slice(AVFilterLink *link, int y, int h, int slice_dir) · 1 unmodified line
401void avfilter_filter_samples(AVFilterLink *link, AVFilterBufferRef *samplesref)399void avfilter_filter_samples(AVFilterLink *link, AVFilterBufferRef *samplesref)
402{400{
403 void (*filter_samples)(AVFilterLink *, AVFilterBufferRef *);401 void (*filter_samples)(AVFilterLink *, AVFilterBufferRef *);
404 AVFilterPad *dst = &link_dpad(link);402 AVFilterPad *dst = link->dstpad;
405 403
406 if (!(filter_samples = dst->filter_samples))404 if (!(filter_samples = dst->filter_samples))
407 filter_samples = avfilter_default_filter_samples;405 filter_samples = avfilter_default_filter_samples;
@@ -412,7 +410,7 @@ void avfilter_filter_samples(AVFilterLink *link, AVFilterBufferRef *samplesref) · 4 unmodified lines
412 410
413 av_log(link->dst, AV_LOG_DEBUG,411 av_log(link->dst, AV_LOG_DEBUG,
414 "Copying audio data in avfilter (have perms %x, need %x, reject %x)\n",412 "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);
416 414
417 link->cur_buf = avfilter_default_get_audio_buffer(link, dst->min_perms,415 link->cur_buf = avfilter_default_get_audio_buffer(link, dst->min_perms,
418 samplesref->format,416 samplesref->format,
@@ -534,7 +532,7 @@ void avfilter_destroy(AVFilterContext *filter) · 115 unmodified lines
534 for (i = 0; i < filter->input_count; i++) {532 for (i = 0; i < filter->input_count; i++) {
535 if ((link = filter->inputs[i])) {533 if ((link = filter->inputs[i])) {
536 if (link->src)534 if (link->src)
537 link->src->outputs[link->srcpad] = NULL;535 link->src->outputs[link->srcpad - link->src->output_pads] = NULL;
538 avfilter_formats_unref(&link->in_formats);536 avfilter_formats_unref(&link->in_formats);
539 avfilter_formats_unref(&link->out_formats);537 avfilter_formats_unref(&link->out_formats);
540 }538 }
@@ -543,7 +541,7 @@ void avfilter_destroy(AVFilterContext *filter) · 2 unmodified lines
543 for (i = 0; i < filter->output_count; i++) {541 for (i = 0; i < filter->output_count; i++) {
544 if ((link = filter->outputs[i])) {542 if ((link = filter->outputs[i])) {
545 if (link->dst)543 if (link->dst)
546 link->dst->inputs[link->dstpad] = NULL;544 link->dst->inputs[link->dstpad - link->dst->input_pads] = NULL;
547 avfilter_formats_unref(&link->in_formats);545 avfilter_formats_unref(&link->in_formats);
548 avfilter_formats_unref(&link->out_formats);546 avfilter_formats_unref(&link->out_formats);
549 }547 }

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