It can be used to directly pass a AVFilterBufferRef to lavfi, avoiding a
memcpy.
| ... | ... |
@@ -3,7 +3,7 @@ FFLIBS = avutil |
| 3 | 3 |
FFLIBS-$(CONFIG_MOVIE_FILTER) += avformat avcodec |
| 4 | 4 |
FFLIBS-$(CONFIG_SCALE_FILTER) += swscale |
| 5 | 5 |
|
| 6 |
-HEADERS = avfilter.h avfiltergraph.h vsrc_buffer.h |
|
| 6 |
+HEADERS = avfilter.h avfiltergraph.h buffersrc.h vsrc_buffer.h |
|
| 7 | 7 |
|
| 8 | 8 |
OBJS = allfilters.o \ |
| 9 | 9 |
avfilter.o \ |
| 10 | 10 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,38 @@ |
| 0 |
+/* |
|
| 1 |
+ * |
|
| 2 |
+ * This file is part of Libav. |
|
| 3 |
+ * |
|
| 4 |
+ * Libav is free software; you can redistribute it and/or |
|
| 5 |
+ * modify it under the terms of the GNU Lesser General Public |
|
| 6 |
+ * License as published by the Free Software Foundation; either |
|
| 7 |
+ * version 2.1 of the License, or (at your option) any later version. |
|
| 8 |
+ * |
|
| 9 |
+ * Libav is distributed in the hope that it will be useful, |
|
| 10 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 11 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
| 12 |
+ * Lesser General Public License for more details. |
|
| 13 |
+ * |
|
| 14 |
+ * You should have received a copy of the GNU Lesser General Public |
|
| 15 |
+ * License along with Libav; if not, write to the Free Software |
|
| 16 |
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|
| 17 |
+ */ |
|
| 18 |
+ |
|
| 19 |
+#ifndef AVFILTER_BUFFERSRC_H |
|
| 20 |
+#define AVFILTER_BUFFERSRC_H |
|
| 21 |
+ |
|
| 22 |
+/** |
|
| 23 |
+ * @file |
|
| 24 |
+ * Memory buffer source API. |
|
| 25 |
+ */ |
|
| 26 |
+ |
|
| 27 |
+#include "avfilter.h" |
|
| 28 |
+ |
|
| 29 |
+/** |
|
| 30 |
+ * Add a buffer to the filtergraph s. |
|
| 31 |
+ * |
|
| 32 |
+ * @param buf buffer containing frame data to be passed down the filtergraph. |
|
| 33 |
+ * This function will take ownership of buf, the user must not free it. |
|
| 34 |
+ */ |
|
| 35 |
+int av_buffersrc_buffer(AVFilterContext *s, AVFilterBufferRef *buf); |
|
| 36 |
+ |
|
| 37 |
+#endif /* AVFILTER_BUFFERSRC_H */ |
| ... | ... |
@@ -24,13 +24,12 @@ |
| 24 | 24 |
*/ |
| 25 | 25 |
|
| 26 | 26 |
#include "avfilter.h" |
| 27 |
+#include "buffersrc.h" |
|
| 27 | 28 |
#include "vsrc_buffer.h" |
| 28 | 29 |
#include "libavutil/imgutils.h" |
| 29 | 30 |
|
| 30 | 31 |
typedef struct {
|
| 31 |
- int64_t pts; |
|
| 32 |
- AVFrame frame; |
|
| 33 |
- int has_frame; |
|
| 32 |
+ AVFilterBufferRef *buf; |
|
| 34 | 33 |
int h, w; |
| 35 | 34 |
enum PixelFormat pix_fmt; |
| 36 | 35 |
AVRational time_base; ///< time_base to set in the output link |
| ... | ... |
@@ -42,7 +41,7 @@ int av_vsrc_buffer_add_frame(AVFilterContext *buffer_filter, AVFrame *frame, |
| 42 | 42 |
{
|
| 43 | 43 |
BufferSourceContext *c = buffer_filter->priv; |
| 44 | 44 |
|
| 45 |
- if (c->has_frame) {
|
|
| 45 |
+ if (c->buf) {
|
|
| 46 | 46 |
av_log(buffer_filter, AV_LOG_ERROR, |
| 47 | 47 |
"Buffering several frames is not supported. " |
| 48 | 48 |
"Please consume all available frames before adding a new one.\n" |
| ... | ... |
@@ -50,15 +49,31 @@ int av_vsrc_buffer_add_frame(AVFilterContext *buffer_filter, AVFrame *frame, |
| 50 | 50 |
//return -1; |
| 51 | 51 |
} |
| 52 | 52 |
|
| 53 |
- memcpy(c->frame.data , frame->data , sizeof(frame->data)); |
|
| 54 |
- memcpy(c->frame.linesize, frame->linesize, sizeof(frame->linesize)); |
|
| 55 |
- c->frame.interlaced_frame= frame->interlaced_frame; |
|
| 56 |
- c->frame.top_field_first = frame->top_field_first; |
|
| 57 |
- c->frame.key_frame = frame->key_frame; |
|
| 58 |
- c->frame.pict_type = frame->pict_type; |
|
| 59 |
- c->pts = pts; |
|
| 60 |
- c->pixel_aspect = pixel_aspect; |
|
| 61 |
- c->has_frame = 1; |
|
| 53 |
+ c->buf = avfilter_get_video_buffer(buffer_filter->outputs[0], AV_PERM_WRITE, |
|
| 54 |
+ c->w, c->h); |
|
| 55 |
+ av_image_copy(c->buf->data, c->buf->linesize, frame->data, frame->linesize, |
|
| 56 |
+ c->pix_fmt, c->w, c->h); |
|
| 57 |
+ |
|
| 58 |
+ avfilter_copy_frame_props(c->buf, frame); |
|
| 59 |
+ c->buf->pts = pts; |
|
| 60 |
+ c->buf->video->pixel_aspect = pixel_aspect; |
|
| 61 |
+ |
|
| 62 |
+ return 0; |
|
| 63 |
+} |
|
| 64 |
+ |
|
| 65 |
+int av_buffersrc_buffer(AVFilterContext *s, AVFilterBufferRef *buf) |
|
| 66 |
+{
|
|
| 67 |
+ BufferSourceContext *c = s->priv; |
|
| 68 |
+ |
|
| 69 |
+ if (c->buf) {
|
|
| 70 |
+ av_log(s, AV_LOG_ERROR, |
|
| 71 |
+ "Buffering several frames is not supported. " |
|
| 72 |
+ "Please consume all available frames before adding a new one.\n" |
|
| 73 |
+ ); |
|
| 74 |
+ return AVERROR(EINVAL); |
|
| 75 |
+ } |
|
| 76 |
+ |
|
| 77 |
+ c->buf = buf; |
|
| 62 | 78 |
|
| 63 | 79 |
return 0; |
| 64 | 80 |
} |
| ... | ... |
@@ -113,33 +128,18 @@ static int config_props(AVFilterLink *link) |
| 113 | 113 |
static int request_frame(AVFilterLink *link) |
| 114 | 114 |
{
|
| 115 | 115 |
BufferSourceContext *c = link->src->priv; |
| 116 |
- AVFilterBufferRef *picref; |
|
| 117 | 116 |
|
| 118 |
- if (!c->has_frame) {
|
|
| 117 |
+ if (!c->buf) {
|
|
| 119 | 118 |
av_log(link->src, AV_LOG_ERROR, |
| 120 | 119 |
"request_frame() called with no available frame!\n"); |
| 121 | 120 |
//return -1; |
| 122 | 121 |
} |
| 123 | 122 |
|
| 124 |
- /* This picture will be needed unmodified later for decoding the next |
|
| 125 |
- * frame */ |
|
| 126 |
- picref = avfilter_get_video_buffer(link, AV_PERM_WRITE | AV_PERM_PRESERVE | |
|
| 127 |
- AV_PERM_REUSE2, |
|
| 128 |
- link->w, link->h); |
|
| 129 |
- |
|
| 130 |
- av_image_copy(picref->data, picref->linesize, |
|
| 131 |
- c->frame.data, c->frame.linesize, |
|
| 132 |
- picref->format, link->w, link->h); |
|
| 133 |
- |
|
| 134 |
- avfilter_copy_frame_props(picref, &c->frame); |
|
| 135 |
- picref->pts = c->pts; |
|
| 136 |
- picref->video->pixel_aspect = c->pixel_aspect; |
|
| 137 |
- avfilter_start_frame(link, avfilter_ref_buffer(picref, ~0)); |
|
| 123 |
+ avfilter_start_frame(link, avfilter_ref_buffer(c->buf, ~0)); |
|
| 138 | 124 |
avfilter_draw_slice(link, 0, link->h, 1); |
| 139 | 125 |
avfilter_end_frame(link); |
| 140 |
- avfilter_unref_buffer(picref); |
|
| 141 |
- |
|
| 142 |
- c->has_frame = 0; |
|
| 126 |
+ avfilter_unref_buffer(c->buf); |
|
| 127 |
+ c->buf = NULL; |
|
| 143 | 128 |
|
| 144 | 129 |
return 0; |
| 145 | 130 |
} |
| ... | ... |
@@ -147,7 +147,7 @@ static int request_frame(AVFilterLink *link) |
| 147 | 147 |
static int poll_frame(AVFilterLink *link) |
| 148 | 148 |
{
|
| 149 | 149 |
BufferSourceContext *c = link->src->priv; |
| 150 |
- return !!(c->has_frame); |
|
| 150 |
+ return !!(c->buf); |
|
| 151 | 151 |
} |
| 152 | 152 |
|
| 153 | 153 |
AVFilter avfilter_vsrc_buffer = {
|