Showing the changes to libavfilter/buffer.c (1 of 3 files). Show all
Unified · Split
| @@ -22,10 +22,12 @@ · 21 unmodified lines | ||
| 22 | 22 | |
| 23 | 23 | #include "libavutil/audioconvert.h" |
| 24 | 24 | #include "libavutil/avassert.h" |
| 25 | +#include "libavutil/imgutils.h" | |
| 25 | 26 | #include "libavcodec/avcodec.h" |
| 26 | 27 | |
| 27 | 28 | #include "avfilter.h" |
| 28 | 29 | #include "internal.h" |
| 30 | +#include "audio.h" | |
| 29 | 31 | #include "avcodec.h" |
| 30 | 32 | |
| 31 | 33 | void ff_avfilter_default_free_buffer(AVFilterBuffer *ptr) |
| @@ -175,3 +177,40 @@ void avfilter_copy_buffer_ref_props(AVFilterBufferRef *dst, AVFilterBufferRef *s · 143 unmodified lines | ||
| 175 | 177 | default: break; |
| 176 | 178 | } |
| 177 | 179 | } |
| 180 | + | |
| 181 | +AVFilterBufferRef *ff_copy_buffer_ref(AVFilterLink *outlink, | |
| 182 | + AVFilterBufferRef *ref) | |
| 183 | +{ | |
| 184 | + AVFilterBufferRef *buf; | |
| 185 | + int channels; | |
| 186 | + | |
| 187 | + switch (outlink->type) { | |
| 188 | + | |
| 189 | + case AVMEDIA_TYPE_VIDEO: | |
| 190 | + buf = ff_get_video_buffer(outlink, AV_PERM_WRITE, | |
| 191 | + ref->video->w, ref->video->h); | |
| 192 | + if(!buf) | |
| 193 | + return NULL; | |
| 194 | + av_image_copy(buf->data, buf->linesize, | |
| 195 | + (void*)ref->data, ref->linesize, | |
| 196 | + ref->format, ref->video->w, ref->video->h); | |
| 197 | + break; | |
| 198 | + | |
| 199 | + case AVMEDIA_TYPE_AUDIO: | |
| 200 | + buf = ff_get_audio_buffer(outlink, AV_PERM_WRITE, | |
| 201 | + ref->audio->nb_samples); | |
| 202 | + if(!buf) | |
| 203 | + return NULL; | |
| 204 | + channels = av_get_channel_layout_nb_channels(ref->audio->channel_layout); | |
| 205 | + av_samples_copy(buf->extended_data, ref->buf->extended_data, | |
| 206 | + 0, 0, ref->audio->nb_samples, | |
| 207 | + channels, | |
| 208 | + ref->format); | |
| 209 | + break; | |
| 210 | + | |
| 211 | + default: | |
| 212 | + return NULL; | |
| 213 | + } | |
| 214 | + avfilter_copy_buffer_ref_props(buf, ref); | |
| 215 | + return buf; | |
| 216 | +} | |