From f810ca63f804cd9f9da5e7a788ecc5b638b706c0 Mon Sep 17 00:00:00 2001 From: Nicolas George Date: Thu, 14 Mar 2013 21:54:48 +0100 Subject: [PATCH 1/4] lavfi: detect merge failure for unknown layouts. Detect when filtering known layouts from an explicit list results in an empty list. Fix erratic behavior. --- libavfilter/formats.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libavfilter/formats.c b/libavfilter/formats.c index 43718e4655..ea2462793e 100644 --- a/libavfilter/formats.c +++ b/libavfilter/formats.c @@ -184,6 +184,10 @@ AVFilterChannelLayouts *ff_merge_channel_layouts(AVFilterChannelLayouts *a, for (i = j = 0; i < b->nb_channel_layouts; i++) if (KNOWN(b->channel_layouts[i])) b->channel_layouts[j++] = b->channel_layouts[i]; + /* Not optimal: the unknown layouts of b may become known after + another merge. */ + if (!j) + return NULL; b->nb_channel_layouts = j; } MERGE_REF(b, a, channel_layouts, AVFilterChannelLayouts, fail); From 9dd54d74226eaaa1087ba994ba212bf9a107c97d Mon Sep 17 00:00:00 2001 From: Nicolas George Date: Wed, 27 Mar 2013 11:11:31 +0100 Subject: [PATCH 2/4] lavd/v4l2: fully init an ioctl argument. Silence a valgrind warning about uninitialized memory. --- libavdevice/v4l2.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libavdevice/v4l2.c b/libavdevice/v4l2.c index 284b495cd9..34e3d9cf42 100644 --- a/libavdevice/v4l2.c +++ b/libavdevice/v4l2.c @@ -949,11 +949,10 @@ static int v4l2_read_header(AVFormatContext *s1) } if (!s->width && !s->height) { - struct v4l2_format fmt; + struct v4l2_format fmt = { .type = V4L2_BUF_TYPE_VIDEO_CAPTURE }; av_log(s1, AV_LOG_VERBOSE, "Querying the device for the current frame size\n"); - fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; if (v4l2_ioctl(s->fd, VIDIOC_G_FMT, &fmt) < 0) { res = AVERROR(errno); av_log(s1, AV_LOG_ERROR, "ioctl(VIDIOC_G_FMT): %s\n", av_err2str(res)); From 983d04dd40a40d2d099d9c382e84da49fd2fe031 Mon Sep 17 00:00:00 2001 From: Nicolas George Date: Thu, 28 Mar 2013 16:45:12 +0100 Subject: [PATCH 3/4] lavu/opt: make sure av_opt_set_bin() handles NULL/0. --- libavutil/opt.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/libavutil/opt.c b/libavutil/opt.c index fb3b724bd6..ab73913a39 100644 --- a/libavutil/opt.c +++ b/libavutil/opt.c @@ -420,8 +420,8 @@ int av_opt_set_bin(void *obj, const char *name, const uint8_t *val, int len, int if (o->type != AV_OPT_TYPE_BINARY) return AVERROR(EINVAL); - ptr = av_malloc(len); - if (!ptr) + ptr = len ? av_malloc(len) : NULL; + if (len && !ptr) return AVERROR(ENOMEM); dst = (uint8_t **)(((uint8_t *)target_obj) + o->offset); @@ -430,7 +430,8 @@ int av_opt_set_bin(void *obj, const char *name, const uint8_t *val, int len, int av_free(*dst); *dst = ptr; *lendst = len; - memcpy(ptr, val, len); + if (len) + memcpy(ptr, val, len); return 0; } From 52853077ee49db8ecb6f83d0f9a177708b5d93a6 Mon Sep 17 00:00:00 2001 From: Nicolas George Date: Sun, 31 Mar 2013 19:28:11 +0200 Subject: [PATCH 4/4] lavfi/af_asetnsamples: fix EOF handling. Only filter one buffered frame. Correctly return EOF if there is none. --- libavfilter/af_asetnsamples.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/libavfilter/af_asetnsamples.c b/libavfilter/af_asetnsamples.c index 08e5279989..e004453642 100644 --- a/libavfilter/af_asetnsamples.c +++ b/libavfilter/af_asetnsamples.c @@ -171,9 +171,8 @@ static int request_frame(AVFilterLink *outlink) } while (!asns->req_fullfilled && ret >= 0); if (ret == AVERROR_EOF) { - do { - ret = push_samples(outlink); - } while (ret > 0); + ret = push_samples(outlink); + return ret < 0 ? ret : ret > 0 ? 0 : AVERROR_EOF; } return ret;