History

lavfi: use a new field for automatic buffer copy.

The code currently use cur_buf as the target of the copy, but cur_buf can be cleared by the filter if it has given the reference away or stored it elsewhere as soon as start_frame. The code still relies on the fact that the reference is not destroyed until end_frame. All filters currently follow that condition. An av_assert1() is added to check it; it should at least cause very visible errors in valgrind.

Nicolas George committed 14 years ago

Commit 8ef740c1 parent f8574652 files · +25 −4Browse files

Unified · Split

2 files
  1. libavfilter/avfilter.h +9 −0
  2. libavfilter/video.c +16 −4
libavfilter/avfilter.h+9−0
@@ -669,6 +669,15 @@ struct AVFilterLink { · 668 unmodified lines
669669 * called with more samples, it will split them.
670670 */
671671 int max_samples;
672+
673+ /**
674+ * The buffer reference currently being received across the link by the
675+ * destination filter. This is used internally by the filter system to
676+ * allow automatic copying of buffers which do not have sufficient
677+ * permissions for the destination. This should not be accessed directly
678+ * by the filters.
679+ */
680+ AVFilterBufferRef *cur_buf_copy;
672681 };
673682
674683 /**
libavfilter/video.c+16−4
@@ -20,6 +20,7 @@ · 19 unmodified lines
2020 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
2121 */
2222
23+#include "libavutil/avassert.h"
2324 #include "libavutil/imgutils.h"
2425
2526 #include "avfilter.h"
@@ -223,6 +224,7 @@ static void clear_link(AVFilterLink *link) · 197 unmodified lines
223224 avfilter_unref_bufferp(&link->cur_buf);
224225 avfilter_unref_bufferp(&link->src_buf);
225226 avfilter_unref_bufferp(&link->out_buf);
227+ link->cur_buf_copy = NULL; /* we do not own the reference */
226228 }
227229
228230 /* XXX: should we do the duplicating of the picture ref here, instead of
@@ -265,6 +267,8 @@ int ff_start_frame(AVFilterLink *link, AVFilterBufferRef *picref) · 36 unmodified lines
265267 else
266268 link->cur_buf = picref;
267269
270+ link->cur_buf_copy = link->cur_buf;
271+
268272 while(cmd && cmd->time <= picref->pts * av_q2d(link->time_base)){
269273 av_log(link->dst, AV_LOG_DEBUG,
270274 "Processing command time:%f command:%s arg:%s\n",
@@ -278,6 +282,10 @@ int ff_start_frame(AVFilterLink *link, AVFilterBufferRef *picref) · 7 unmodified lines
278282 ff_update_link_current_pts(link, pts);
279283 if (ret < 0)
280284 clear_link(link);
285+ else
286+ /* incoming buffers must not be freed in start frame,
287+ because they can still be in use by the automatic copy mechanism */
288+ av_assert1(link->cur_buf_copy->buf->refcount > 0);
281289
282290 return ret;
283291 }
@@ -348,22 +356,22 @@ int ff_draw_slice(AVFilterLink *link, int y, int h, int slice_dir) · 64 unmodified lines
348356 if (link->src_buf->data[i]) {
349357 src[i] = link->src_buf-> data[i] +
350358 (y >> (i==1 || i==2 ? vsub : 0)) * link->src_buf-> linesize[i];
351− dst[i] = link->cur_buf->data[i] +
352− (y >> (i==1 || i==2 ? vsub : 0)) * link->cur_buf->linesize[i];
359+ dst[i] = link->cur_buf_copy->data[i] +
360+ (y >> (i==1 || i==2 ? vsub : 0)) * link->cur_buf_copy->linesize[i];
353361 } else
354362 src[i] = dst[i] = NULL;
355363 }
356364
357365 for (i = 0; i < 4; i++) {
358366 int planew =
359− av_image_get_linesize(link->format, link->cur_buf->video->w, i);
367+ av_image_get_linesize(link->format, link->cur_buf_copy->video->w, i);
360368
361369 if (!src[i]) continue;
362370
363371 for (j = 0; j < h >> (i==1 || i==2 ? vsub : 0); j++) {
364372 memcpy(dst[i], src[i], planew);
365373 src[i] += link->src_buf->linesize[i];
366− dst[i] += link->cur_buf->linesize[i];
374+ dst[i] += link->cur_buf_copy->linesize[i];
367375 }
368376 }
369377 }
@@ -373,6 +381,10 @@ int ff_draw_slice(AVFilterLink *link, int y, int h, int slice_dir) · 3 unmodified lines
373381 ret = draw_slice(link, y, h, slice_dir);
374382 if (ret < 0)
375383 clear_link(link);
384+ else
385+ /* incoming buffers must not be freed in start frame,
386+ because they can still be in use by the automatic copy mechanism */
387+ av_assert1(link->cur_buf_copy->buf->refcount > 0);
376388 return ret;
377389 }
378390

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