The new flags parameter allows to specify if the video ref to add should overwrite the cache, if the flag is not set vsrc_buffer will complain and abort; otherwise it will clean the already cached video ref before to overwrite it, thus avoiding a leak.tags/n0.8
| @@ -13,6 +13,10 @@ libavutil: 2011-04-18 | |||||
| API changes, most recent first: | API changes, most recent first: | ||||
| 2011-06-06 - xxxxxx - lavfi 2.13.0 - vsrc_buffer.h | |||||
| Make av_vsrc_buffer_add_video_buffer_ref() accepts an additional | |||||
| flags parameter in input. | |||||
| 2011-06-03 - xxxxxx - lavfi 2.12.0 - avfilter_link_free() | 2011-06-03 - xxxxxx - lavfi 2.12.0 - avfilter_link_free() | ||||
| Add avfilter_link_free() function. | Add avfilter_link_free() function. | ||||
| @@ -1691,7 +1691,8 @@ static int output_packet(AVInputStream *ist, int ist_index, | |||||
| picture.sample_aspect_ratio = ist->st->sample_aspect_ratio; | picture.sample_aspect_ratio = ist->st->sample_aspect_ratio; | ||||
| picture.pts = ist->pts; | picture.pts = ist->pts; | ||||
| av_vsrc_buffer_add_frame(ost->input_video_filter, &picture); | |||||
| av_vsrc_buffer_add_frame(ost->input_video_filter, | |||||
| &picture, AV_VSRC_BUF_FLAG_OVERWRITE); | |||||
| } | } | ||||
| frame_available = ist->st->codec->codec_type != AVMEDIA_TYPE_VIDEO || | frame_available = ist->st->codec->codec_type != AVMEDIA_TYPE_VIDEO || | ||||
| !ost->output_video_filter || avfilter_poll_frame(ost->output_video_filter->inputs[0]); | !ost->output_video_filter || avfilter_poll_frame(ost->output_video_filter->inputs[0]); | ||||
| @@ -30,6 +30,7 @@ | |||||
| #include "libavcodec/avcodec.h" // AVFrame | #include "libavcodec/avcodec.h" // AVFrame | ||||
| #include "avfilter.h" | #include "avfilter.h" | ||||
| #include "vsrc_buffer.h" | |||||
| /** | /** | ||||
| * Copy the frame properties of src to dst, without copying the actual | * Copy the frame properties of src to dst, without copying the actual | ||||
| @@ -49,9 +50,11 @@ AVFilterBufferRef *avfilter_get_video_buffer_ref_from_frame(const AVFrame *frame | |||||
| * Add frame data to buffer_src. | * Add frame data to buffer_src. | ||||
| * | * | ||||
| * @param buffer_src pointer to a buffer source context | * @param buffer_src pointer to a buffer source context | ||||
| * @param flags a combination of AV_VSRC_BUF_FLAG_* flags | |||||
| * @return >= 0 in case of success, a negative AVERROR code in case of | * @return >= 0 in case of success, a negative AVERROR code in case of | ||||
| * failure | * failure | ||||
| */ | */ | ||||
| int av_vsrc_buffer_add_frame(AVFilterContext *buffer_src, const AVFrame *frame); | |||||
| int av_vsrc_buffer_add_frame(AVFilterContext *buffer_src, | |||||
| const AVFrame *frame, int flags); | |||||
| #endif /* AVFILTER_AVCODEC_H */ | #endif /* AVFILTER_AVCODEC_H */ | ||||
| @@ -26,7 +26,7 @@ | |||||
| #include "libavutil/samplefmt.h" | #include "libavutil/samplefmt.h" | ||||
| #define LIBAVFILTER_VERSION_MAJOR 2 | #define LIBAVFILTER_VERSION_MAJOR 2 | ||||
| #define LIBAVFILTER_VERSION_MINOR 12 | |||||
| #define LIBAVFILTER_VERSION_MINOR 13 | |||||
| #define LIBAVFILTER_VERSION_MICRO 0 | #define LIBAVFILTER_VERSION_MICRO 0 | ||||
| #define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \ | #define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \ | ||||
| @@ -37,18 +37,23 @@ typedef struct { | |||||
| char sws_param[256]; | char sws_param[256]; | ||||
| } BufferSourceContext; | } BufferSourceContext; | ||||
| int av_vsrc_buffer_add_video_buffer_ref(AVFilterContext *buffer_filter, AVFilterBufferRef *picref) | |||||
| int av_vsrc_buffer_add_video_buffer_ref(AVFilterContext *buffer_filter, | |||||
| AVFilterBufferRef *picref, int flags) | |||||
| { | { | ||||
| BufferSourceContext *c = buffer_filter->priv; | BufferSourceContext *c = buffer_filter->priv; | ||||
| AVFilterLink *outlink = buffer_filter->outputs[0]; | AVFilterLink *outlink = buffer_filter->outputs[0]; | ||||
| int ret; | int ret; | ||||
| if (c->picref) { | if (c->picref) { | ||||
| av_log(buffer_filter, AV_LOG_ERROR, | |||||
| "Buffering several frames is not supported. " | |||||
| "Please consume all available frames before adding a new one.\n" | |||||
| ); | |||||
| //return -1; | |||||
| if (flags & AV_VSRC_BUF_FLAG_OVERWRITE) { | |||||
| avfilter_unref_buffer(c->picref); | |||||
| c->picref = NULL; | |||||
| } else { | |||||
| av_log(buffer_filter, AV_LOG_ERROR, | |||||
| "Buffering several frames is not supported. " | |||||
| "Please consume all available frames before adding a new one.\n"); | |||||
| return AVERROR(EINVAL); | |||||
| } | |||||
| } | } | ||||
| if (picref->video->w != c->w || picref->video->h != c->h || picref->format != c->pix_fmt) { | if (picref->video->w != c->w || picref->video->h != c->h || picref->format != c->pix_fmt) { | ||||
| @@ -109,14 +114,15 @@ int av_vsrc_buffer_add_video_buffer_ref(AVFilterContext *buffer_filter, AVFilter | |||||
| #if CONFIG_AVCODEC | #if CONFIG_AVCODEC | ||||
| #include "avcodec.h" | #include "avcodec.h" | ||||
| int av_vsrc_buffer_add_frame(AVFilterContext *buffer_src, const AVFrame *frame) | |||||
| int av_vsrc_buffer_add_frame(AVFilterContext *buffer_src, | |||||
| const AVFrame *frame, int flags) | |||||
| { | { | ||||
| int ret; | int ret; | ||||
| AVFilterBufferRef *picref = | AVFilterBufferRef *picref = | ||||
| avfilter_get_video_buffer_ref_from_frame(frame, AV_PERM_WRITE); | avfilter_get_video_buffer_ref_from_frame(frame, AV_PERM_WRITE); | ||||
| if (!picref) | if (!picref) | ||||
| return AVERROR(ENOMEM); | return AVERROR(ENOMEM); | ||||
| ret = av_vsrc_buffer_add_video_buffer_ref(buffer_src, picref); | |||||
| ret = av_vsrc_buffer_add_video_buffer_ref(buffer_src, picref, flags); | |||||
| picref->buf->data[0] = NULL; | picref->buf->data[0] = NULL; | ||||
| avfilter_unref_buffer(picref); | avfilter_unref_buffer(picref); | ||||
| @@ -28,13 +28,22 @@ | |||||
| #include "avfilter.h" | #include "avfilter.h" | ||||
| /** | |||||
| * Tell av_vsrc_buffer_add_video_buffer_ref() to overwrite the already | |||||
| * cached video buffer with the new added one, otherwise the function | |||||
| * will complain and exit. | |||||
| */ | |||||
| #define AV_VSRC_BUF_FLAG_OVERWRITE 1 | |||||
| /** | /** | ||||
| * Add video buffer data in picref to buffer_src. | * Add video buffer data in picref to buffer_src. | ||||
| * | * | ||||
| * @param buffer_src pointer to a buffer source context | * @param buffer_src pointer to a buffer source context | ||||
| * @param flags a combination of AV_VSRC_BUF_FLAG_* flags | |||||
| * @return >= 0 in case of success, a negative AVERROR code in case of | * @return >= 0 in case of success, a negative AVERROR code in case of | ||||
| * failure | * failure | ||||
| */ | */ | ||||
| int av_vsrc_buffer_add_video_buffer_ref(AVFilterContext *buffer_src, AVFilterBufferRef *picref); | |||||
| int av_vsrc_buffer_add_video_buffer_ref(AVFilterContext *buffer_src, | |||||
| AVFilterBufferRef *picref, int flags); | |||||
| #endif /* AVFILTER_VSRC_BUFFER_H */ | #endif /* AVFILTER_VSRC_BUFFER_H */ | ||||