From 42c26a4864f1cefa4175c6c171aa0e4bd88dd42d Mon Sep 17 00:00:00 2001 From: Luca Barbato Date: Wed, 24 Oct 2012 14:18:49 +0200 Subject: [PATCH 1/6] rawvideo: use a specific read_header ff_raw_read_header is used only for this demuxer for video. --- libavformat/Makefile | 2 +- libavformat/rawvideodec.c | 68 +++++++++++++++++++++++++++++++++++---- 2 files changed, 62 insertions(+), 8 deletions(-) diff --git a/libavformat/Makefile b/libavformat/Makefile index 2d66a6d0ba..a285af1bb2 100644 --- a/libavformat/Makefile +++ b/libavformat/Makefile @@ -239,7 +239,7 @@ OBJS-$(CONFIG_PMP_DEMUXER) += pmpdec.o OBJS-$(CONFIG_PVA_DEMUXER) += pva.o OBJS-$(CONFIG_QCP_DEMUXER) += qcp.o OBJS-$(CONFIG_R3D_DEMUXER) += r3d.o -OBJS-$(CONFIG_RAWVIDEO_DEMUXER) += rawvideodec.o rawdec.o +OBJS-$(CONFIG_RAWVIDEO_DEMUXER) += rawvideodec.o OBJS-$(CONFIG_RAWVIDEO_MUXER) += rawenc.o OBJS-$(CONFIG_RL2_DEMUXER) += rl2.o OBJS-$(CONFIG_RM_DEMUXER) += rmdec.o rm.o rmsipr.o diff --git a/libavformat/rawvideodec.c b/libavformat/rawvideodec.c index f71ea0a73e..5f372c9a2c 100644 --- a/libavformat/rawvideodec.c +++ b/libavformat/rawvideodec.c @@ -19,8 +19,63 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include "libavutil/parseutils.h" +#include "libavutil/pixdesc.h" +#include "libavutil/opt.h" +#include "internal.h" #include "avformat.h" -#include "rawdec.h" + +typedef struct RawVideoDemuxerContext { + const AVClass *class; /**< Class for private options. */ + char *video_size; /**< String describing video size, set by a private option. */ + char *pixel_format; /**< Set by a private option. */ + char *framerate; /**< String describing framerate, set by a private option. */ +} RawVideoDemuxerContext; + + +static int rawvideo_read_header(AVFormatContext *ctx) +{ + RawVideoDemuxerContext *s = ctx->priv_data; + int width = 0, height = 0, ret = 0; + enum AVPixelFormat pix_fmt; + AVRational framerate; + AVStream *st; + + st = avformat_new_stream(ctx, NULL); + if (!st) + return AVERROR(ENOMEM); + + st->codec->codec_type = AVMEDIA_TYPE_VIDEO; + + st->codec->codec_id = ctx->iformat->raw_codec_id; + + if (s->video_size && + (ret = av_parse_video_size(&width, &height, s->video_size)) < 0) { + av_log(ctx, AV_LOG_ERROR, "Couldn't parse video size.\n"); + return ret; + } + + if ((pix_fmt = av_get_pix_fmt(s->pixel_format)) == AV_PIX_FMT_NONE) { + av_log(ctx, AV_LOG_ERROR, "No such pixel format: %s.\n", + s->pixel_format); + return AVERROR(EINVAL); + } + + if ((ret = av_parse_video_rate(&framerate, s->framerate)) < 0) { + av_log(ctx, AV_LOG_ERROR, "Could not parse framerate: %s.\n", + s->framerate); + return ret; + } + + avpriv_set_pts_info(st, 64, framerate.den, framerate.num); + + st->codec->width = width; + st->codec->height = height; + st->codec->pix_fmt = pix_fmt; + + return 0; +} + static int rawvideo_read_packet(AVFormatContext *s, AVPacket *pkt) { @@ -34,9 +89,8 @@ static int rawvideo_read_packet(AVFormatContext *s, AVPacket *pkt) if (packet_size < 0) return -1; - ret= av_get_packet(s->pb, pkt, packet_size); - pkt->pts= - pkt->dts= pkt->pos / packet_size; + ret = av_get_packet(s->pb, pkt, packet_size); + pkt->pts = pkt->dts = pkt->pos / packet_size; pkt->stream_index = 0; if (ret < 0) @@ -44,7 +98,7 @@ static int rawvideo_read_packet(AVFormatContext *s, AVPacket *pkt) return 0; } -#define OFFSET(x) offsetof(FFRawVideoDemuxerContext, x) +#define OFFSET(x) offsetof(RawVideoDemuxerContext, x) #define DEC AV_OPT_FLAG_DECODING_PARAM static const AVOption rawvideo_options[] = { { "video_size", "A string describing frame size, such as 640x480 or hd720.", OFFSET(video_size), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC }, @@ -63,8 +117,8 @@ static const AVClass rawvideo_demuxer_class = { AVInputFormat ff_rawvideo_demuxer = { .name = "rawvideo", .long_name = NULL_IF_CONFIG_SMALL("raw video"), - .priv_data_size = sizeof(FFRawVideoDemuxerContext), - .read_header = ff_raw_read_header, + .priv_data_size = sizeof(RawVideoDemuxerContext), + .read_header = rawvideo_read_header, .read_packet = rawvideo_read_packet, .flags = AVFMT_GENERIC_INDEX, .extensions = "yuv,cif,qcif,rgb", From 5f0e161dd61552ad70760bad35b869eaec7368ff Mon Sep 17 00:00:00 2001 From: Luca Barbato Date: Wed, 24 Oct 2012 18:18:18 +0200 Subject: [PATCH 2/6] g722: refactor out of rawdec.c --- libavformat/Makefile | 2 +- libavformat/g722.c | 56 ++++++++++++++++++++++++++++++++++++++++++++ libavformat/rawdec.c | 12 ---------- 3 files changed, 57 insertions(+), 13 deletions(-) create mode 100644 libavformat/g722.c diff --git a/libavformat/Makefile b/libavformat/Makefile index a285af1bb2..832ea41939 100644 --- a/libavformat/Makefile +++ b/libavformat/Makefile @@ -101,7 +101,7 @@ OBJS-$(CONFIG_GIF_MUXER) += gif.o OBJS-$(CONFIG_GSM_DEMUXER) += gsmdec.o OBJS-$(CONFIG_GXF_DEMUXER) += gxf.o OBJS-$(CONFIG_GXF_MUXER) += gxfenc.o audiointerleave.o -OBJS-$(CONFIG_G722_DEMUXER) += rawdec.o +OBJS-$(CONFIG_G722_DEMUXER) += g722.o rawdec.o OBJS-$(CONFIG_G722_MUXER) += rawenc.o OBJS-$(CONFIG_G723_1_DEMUXER) += g723_1.o OBJS-$(CONFIG_H261_DEMUXER) += h261dec.o rawdec.o diff --git a/libavformat/g722.c b/libavformat/g722.c new file mode 100644 index 0000000000..8052939c79 --- /dev/null +++ b/libavformat/g722.c @@ -0,0 +1,56 @@ +/* + * g722 raw demuxer + * Copyright (c) 2010 Martin Storsjo + * + * This file is part of Libav. + * + * Libav is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * Libav is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with Libav; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "avformat.h" +#include "internal.h" +#include "rawdec.h" + +static int g722_read_header(AVFormatContext *s) +{ + AVStream *st; + + st = avformat_new_stream(s, NULL); + if (!st) + return AVERROR(ENOMEM); + + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; + st->codec->codec_id = AV_CODEC_ID_ADPCM_G722; + st->codec->sample_rate = 16000; + st->codec->channels = 1; + + st->codec->bits_per_coded_sample = + av_get_bits_per_sample(st->codec->codec_id); + + assert(st->codec->bits_per_coded_sample > 0); + + avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate); + return 0; +} + +AVInputFormat ff_g722_demuxer = { + .name = "g722", + .long_name = NULL_IF_CONFIG_SMALL("raw G.722"), + .read_header = g722_read_header, + .read_packet = ff_raw_read_partial_packet, + .flags = AVFMT_GENERIC_INDEX, + .extensions = "g722,722", + .raw_codec_id = AV_CODEC_ID_ADPCM_G722, +}; diff --git a/libavformat/rawdec.c b/libavformat/rawdec.c index 7ea3d2b8fc..fd1e9b967f 100644 --- a/libavformat/rawdec.c +++ b/libavformat/rawdec.c @@ -177,18 +177,6 @@ const AVOption ff_rawvideo_options[] = { { NULL }, }; -#if CONFIG_G722_DEMUXER -AVInputFormat ff_g722_demuxer = { - .name = "g722", - .long_name = NULL_IF_CONFIG_SMALL("raw G.722"), - .read_header = ff_raw_read_header, - .read_packet = ff_raw_read_partial_packet, - .flags = AVFMT_GENERIC_INDEX, - .extensions = "g722,722", - .raw_codec_id = AV_CODEC_ID_ADPCM_G722, -}; -#endif - #if CONFIG_LATM_DEMUXER AVInputFormat ff_latm_demuxer = { .name = "latm", From 2ef4d586d6352a69c0669d53ce1035eb7d8db0e8 Mon Sep 17 00:00:00 2001 From: Luca Barbato Date: Wed, 24 Oct 2012 19:15:50 +0200 Subject: [PATCH 3/6] pcmdec: remove dependency from rawdec The code shared is not actually shared with anything else. --- libavformat/Makefile | 40 ++++++++++++++++++++-------------------- libavformat/pcmdec.c | 37 +++++++++++++++++++++++++++++++++++-- 2 files changed, 55 insertions(+), 22 deletions(-) diff --git a/libavformat/Makefile b/libavformat/Makefile index 832ea41939..acf0500de1 100644 --- a/libavformat/Makefile +++ b/libavformat/Makefile @@ -195,45 +195,45 @@ OBJS-$(CONFIG_OGG_MUXER) += oggenc.o \ vorbiscomment.o OBJS-$(CONFIG_OMA_DEMUXER) += omadec.o pcm.o oma.o OBJS-$(CONFIG_OMA_MUXER) += omaenc.o rawenc.o oma.o id3v2enc.o -OBJS-$(CONFIG_PCM_ALAW_DEMUXER) += pcmdec.o pcm.o rawdec.o +OBJS-$(CONFIG_PCM_ALAW_DEMUXER) += pcmdec.o pcm.o OBJS-$(CONFIG_PCM_ALAW_MUXER) += pcmenc.o rawenc.o -OBJS-$(CONFIG_PCM_F32BE_DEMUXER) += pcmdec.o pcm.o rawdec.o +OBJS-$(CONFIG_PCM_F32BE_DEMUXER) += pcmdec.o pcm.o OBJS-$(CONFIG_PCM_F32BE_MUXER) += pcmenc.o rawenc.o -OBJS-$(CONFIG_PCM_F32LE_DEMUXER) += pcmdec.o pcm.o rawdec.o +OBJS-$(CONFIG_PCM_F32LE_DEMUXER) += pcmdec.o pcm.o OBJS-$(CONFIG_PCM_F32LE_MUXER) += pcmenc.o rawenc.o -OBJS-$(CONFIG_PCM_F64BE_DEMUXER) += pcmdec.o pcm.o rawdec.o +OBJS-$(CONFIG_PCM_F64BE_DEMUXER) += pcmdec.o pcm.o OBJS-$(CONFIG_PCM_F64BE_MUXER) += pcmenc.o rawenc.o -OBJS-$(CONFIG_PCM_F64LE_DEMUXER) += pcmdec.o pcm.o rawdec.o +OBJS-$(CONFIG_PCM_F64LE_DEMUXER) += pcmdec.o pcm.o OBJS-$(CONFIG_PCM_F64LE_MUXER) += pcmenc.o rawenc.o -OBJS-$(CONFIG_PCM_MULAW_DEMUXER) += pcmdec.o pcm.o rawdec.o +OBJS-$(CONFIG_PCM_MULAW_DEMUXER) += pcmdec.o pcm.o OBJS-$(CONFIG_PCM_MULAW_MUXER) += pcmenc.o rawenc.o -OBJS-$(CONFIG_PCM_S16BE_DEMUXER) += pcmdec.o pcm.o rawdec.o +OBJS-$(CONFIG_PCM_S16BE_DEMUXER) += pcmdec.o pcm.o OBJS-$(CONFIG_PCM_S16BE_MUXER) += pcmenc.o rawenc.o -OBJS-$(CONFIG_PCM_S16LE_DEMUXER) += pcmdec.o pcm.o rawdec.o +OBJS-$(CONFIG_PCM_S16LE_DEMUXER) += pcmdec.o pcm.o OBJS-$(CONFIG_PCM_S16LE_MUXER) += pcmenc.o rawenc.o -OBJS-$(CONFIG_PCM_S24BE_DEMUXER) += pcmdec.o pcm.o rawdec.o +OBJS-$(CONFIG_PCM_S24BE_DEMUXER) += pcmdec.o pcm.o OBJS-$(CONFIG_PCM_S24BE_MUXER) += pcmenc.o rawenc.o -OBJS-$(CONFIG_PCM_S24LE_DEMUXER) += pcmdec.o pcm.o rawdec.o +OBJS-$(CONFIG_PCM_S24LE_DEMUXER) += pcmdec.o pcm.o OBJS-$(CONFIG_PCM_S24LE_MUXER) += pcmenc.o rawenc.o -OBJS-$(CONFIG_PCM_S32BE_DEMUXER) += pcmdec.o pcm.o rawdec.o +OBJS-$(CONFIG_PCM_S32BE_DEMUXER) += pcmdec.o pcm.o OBJS-$(CONFIG_PCM_S32BE_MUXER) += pcmenc.o rawenc.o -OBJS-$(CONFIG_PCM_S32LE_DEMUXER) += pcmdec.o pcm.o rawdec.o +OBJS-$(CONFIG_PCM_S32LE_DEMUXER) += pcmdec.o pcm.o OBJS-$(CONFIG_PCM_S32LE_MUXER) += pcmenc.o rawenc.o -OBJS-$(CONFIG_PCM_S8_DEMUXER) += pcmdec.o pcm.o rawdec.o +OBJS-$(CONFIG_PCM_S8_DEMUXER) += pcmdec.o pcm.o OBJS-$(CONFIG_PCM_S8_MUXER) += pcmenc.o rawenc.o -OBJS-$(CONFIG_PCM_U16BE_DEMUXER) += pcmdec.o pcm.o rawdec.o +OBJS-$(CONFIG_PCM_U16BE_DEMUXER) += pcmdec.o pcm.o OBJS-$(CONFIG_PCM_U16BE_MUXER) += pcmenc.o rawenc.o -OBJS-$(CONFIG_PCM_U16LE_DEMUXER) += pcmdec.o pcm.o rawdec.o +OBJS-$(CONFIG_PCM_U16LE_DEMUXER) += pcmdec.o pcm.o OBJS-$(CONFIG_PCM_U16LE_MUXER) += pcmenc.o rawenc.o -OBJS-$(CONFIG_PCM_U24BE_DEMUXER) += pcmdec.o pcm.o rawdec.o +OBJS-$(CONFIG_PCM_U24BE_DEMUXER) += pcmdec.o pcm.o OBJS-$(CONFIG_PCM_U24BE_MUXER) += pcmenc.o rawenc.o -OBJS-$(CONFIG_PCM_U24LE_DEMUXER) += pcmdec.o pcm.o rawdec.o +OBJS-$(CONFIG_PCM_U24LE_DEMUXER) += pcmdec.o pcm.o OBJS-$(CONFIG_PCM_U24LE_MUXER) += pcmenc.o rawenc.o -OBJS-$(CONFIG_PCM_U32BE_DEMUXER) += pcmdec.o pcm.o rawdec.o +OBJS-$(CONFIG_PCM_U32BE_DEMUXER) += pcmdec.o pcm.o OBJS-$(CONFIG_PCM_U32BE_MUXER) += pcmenc.o rawenc.o -OBJS-$(CONFIG_PCM_U32LE_DEMUXER) += pcmdec.o pcm.o rawdec.o +OBJS-$(CONFIG_PCM_U32LE_DEMUXER) += pcmdec.o pcm.o OBJS-$(CONFIG_PCM_U32LE_MUXER) += pcmenc.o rawenc.o -OBJS-$(CONFIG_PCM_U8_DEMUXER) += pcmdec.o pcm.o rawdec.o +OBJS-$(CONFIG_PCM_U8_DEMUXER) += pcmdec.o pcm.o OBJS-$(CONFIG_PCM_U8_MUXER) += pcmenc.o rawenc.o OBJS-$(CONFIG_PMP_DEMUXER) += pmpdec.o OBJS-$(CONFIG_PVA_DEMUXER) += pva.o diff --git a/libavformat/pcmdec.c b/libavformat/pcmdec.c index ad47885297..40446c29e3 100644 --- a/libavformat/pcmdec.c +++ b/libavformat/pcmdec.c @@ -20,13 +20,46 @@ */ #include "avformat.h" -#include "rawdec.h" +#include "internal.h" #include "pcm.h" #include "libavutil/log.h" #include "libavutil/opt.h" #define RAW_SAMPLES 1024 +typedef struct RawAudioDemuxerContext { + AVClass *class; + int sample_rate; + int channels; +} RawAudioDemuxerContext; + +static int raw_read_header(AVFormatContext *s) +{ + RawAudioDemuxerContext *s1 = s->priv_data; + AVStream *st; + + st = avformat_new_stream(s, NULL); + if (!st) + return AVERROR(ENOMEM); + + + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; + st->codec->codec_id = s->iformat->raw_codec_id; + st->codec->sample_rate = s1->sample_rate; + st->codec->channels = s1->channels; + + st->codec->bits_per_coded_sample = + av_get_bits_per_sample(st->codec->codec_id); + + assert(st->codec->bits_per_coded_sample > 0); + + st->codec->block_align = + st->codec->bits_per_coded_sample * st->codec->channels / 8; + + avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate); + return 0; +} + static int raw_read_packet(AVFormatContext *s, AVPacket *pkt) { int ret, size, bps; @@ -65,7 +98,7 @@ AVInputFormat ff_pcm_ ## name_ ## _demuxer = { \ .name = #name_, \ .long_name = NULL_IF_CONFIG_SMALL(long_name_), \ .priv_data_size = sizeof(RawAudioDemuxerContext), \ - .read_header = ff_raw_read_header, \ + .read_header = raw_read_header, \ .read_packet = raw_read_packet, \ .read_seek = ff_pcm_read_seek, \ .flags = AVFMT_GENERIC_INDEX, \ From 587874ef1c94a9b863d2f2db0e5d341e086ee232 Mon Sep 17 00:00:00 2001 From: Luca Barbato Date: Wed, 24 Oct 2012 19:53:32 +0200 Subject: [PATCH 4/6] rawdec: remove ff_raw_read_header It is not used anymore and is a kludge. --- libavformat/rawdec.c | 70 -------------------------------------------- libavformat/rawdec.h | 8 ----- 2 files changed, 78 deletions(-) diff --git a/libavformat/rawdec.c b/libavformat/rawdec.c index fd1e9b967f..1c9aabd6fd 100644 --- a/libavformat/rawdec.c +++ b/libavformat/rawdec.c @@ -28,76 +28,6 @@ #include "libavutil/parseutils.h" #include "libavutil/pixdesc.h" -/* raw input */ -int ff_raw_read_header(AVFormatContext *s) -{ - AVStream *st; - enum AVCodecID id; - - st = avformat_new_stream(s, NULL); - if (!st) - return AVERROR(ENOMEM); - - id = s->iformat->raw_codec_id; - if (id == AV_CODEC_ID_RAWVIDEO) { - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - } else { - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - } - st->codec->codec_id = id; - - switch(st->codec->codec_type) { - case AVMEDIA_TYPE_AUDIO: { - RawAudioDemuxerContext *s1 = s->priv_data; - - st->codec->channels = 1; - - if (id == AV_CODEC_ID_ADPCM_G722) - st->codec->sample_rate = 16000; - - if (s1 && s1->sample_rate) - st->codec->sample_rate = s1->sample_rate; - if (s1 && s1->channels) - st->codec->channels = s1->channels; - - st->codec->bits_per_coded_sample = av_get_bits_per_sample(st->codec->codec_id); - assert(st->codec->bits_per_coded_sample > 0); - st->codec->block_align = st->codec->bits_per_coded_sample*st->codec->channels/8; - avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate); - break; - } - case AVMEDIA_TYPE_VIDEO: { - FFRawVideoDemuxerContext *s1 = s->priv_data; - int width = 0, height = 0, ret = 0; - enum AVPixelFormat pix_fmt; - AVRational framerate; - - if (s1->video_size && (ret = av_parse_video_size(&width, &height, s1->video_size)) < 0) { - av_log(s, AV_LOG_ERROR, "Couldn't parse video size.\n"); - goto fail; - } - if ((pix_fmt = av_get_pix_fmt(s1->pixel_format)) == AV_PIX_FMT_NONE) { - av_log(s, AV_LOG_ERROR, "No such pixel format: %s.\n", s1->pixel_format); - ret = AVERROR(EINVAL); - goto fail; - } - if ((ret = av_parse_video_rate(&framerate, s1->framerate)) < 0) { - av_log(s, AV_LOG_ERROR, "Could not parse framerate: %s.\n", s1->framerate); - goto fail; - } - avpriv_set_pts_info(st, 64, framerate.den, framerate.num); - st->codec->width = width; - st->codec->height = height; - st->codec->pix_fmt = pix_fmt; -fail: - return ret; - } - default: - return -1; - } - return 0; -} - #define RAW_PACKET_SIZE 1024 int ff_raw_read_partial_packet(AVFormatContext *s, AVPacket *pkt) diff --git a/libavformat/rawdec.h b/libavformat/rawdec.h index 4cce2cf901..a5487784c9 100644 --- a/libavformat/rawdec.h +++ b/libavformat/rawdec.h @@ -26,12 +26,6 @@ #include "libavutil/log.h" #include "libavutil/opt.h" -typedef struct RawAudioDemuxerContext { - AVClass *class; - int sample_rate; - int channels; -} RawAudioDemuxerContext; - typedef struct FFRawVideoDemuxerContext { const AVClass *class; /**< Class for private options. */ char *video_size; /**< String describing video size, set by a private option. */ @@ -41,8 +35,6 @@ typedef struct FFRawVideoDemuxerContext { extern const AVOption ff_rawvideo_options[]; -int ff_raw_read_header(AVFormatContext *s); - int ff_raw_read_partial_packet(AVFormatContext *s, AVPacket *pkt); int ff_raw_audio_read_header(AVFormatContext *s); From 285b706b551b94e18f875ed01163926c8b98e68b Mon Sep 17 00:00:00 2001 From: Janne Grunau Date: Tue, 9 Oct 2012 21:28:32 +0200 Subject: [PATCH 5/6] avfilter: fix graphparser memleaks on error paths Fixes CID700635, CID700636 and CID732274. --- libavfilter/graphparser.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/libavfilter/graphparser.c b/libavfilter/graphparser.c index 3921189aa9..04339c8138 100644 --- a/libavfilter/graphparser.c +++ b/libavfilter/graphparser.c @@ -238,10 +238,11 @@ static int link_filter_inouts(AVFilterContext *filt_ctx, return AVERROR(ENOMEM); if (p->filter_ctx) { - if ((ret = link_filter(p->filter_ctx, p->pad_idx, filt_ctx, pad, log_ctx)) < 0) - return ret; + ret = link_filter(p->filter_ctx, p->pad_idx, filt_ctx, pad, log_ctx); av_free(p->name); av_free(p); + if (ret < 0) + return ret; } else { p->filter_ctx = filt_ctx; p->pad_idx = pad; @@ -289,8 +290,10 @@ static int parse_inputs(const char **buf, AVFilterInOut **curr_inputs, av_free(name); } else { /* Not in the list, so add it as an input */ - if (!(match = av_mallocz(sizeof(AVFilterInOut)))) + if (!(match = av_mallocz(sizeof(AVFilterInOut)))) { + av_free(name); return AVERROR(ENOMEM); + } match->name = name; match->pad_idx = pad; } @@ -318,24 +321,27 @@ static int parse_outputs(const char **buf, AVFilterInOut **curr_inputs, AVFilterInOut *match; AVFilterInOut *input = *curr_inputs; - if (!input) { - av_log(log_ctx, AV_LOG_ERROR, - "No output pad can be associated to link label '%s'.\n", - name); - return AVERROR(EINVAL); - } - *curr_inputs = (*curr_inputs)->next; if (!name) return AVERROR(EINVAL); + if (!input) { + av_log(log_ctx, AV_LOG_ERROR, + "No output pad can be associated to link label '%s'.\n", name); + av_free(name); + return AVERROR(EINVAL); + } + *curr_inputs = (*curr_inputs)->next; + /* First check if the label is not in the open_inputs list */ match = extract_inout(name, open_inputs); if (match) { if ((ret = link_filter(input->filter_ctx, input->pad_idx, - match->filter_ctx, match->pad_idx, log_ctx)) < 0) + match->filter_ctx, match->pad_idx, log_ctx)) < 0) { + av_free(name); return ret; + } av_free(match->name); av_free(name); av_free(match); From 1b891d17c531e8a63c2974aab4bf997ce70746f3 Mon Sep 17 00:00:00 2001 From: Janne Grunau Date: Tue, 9 Oct 2012 23:22:49 +0200 Subject: [PATCH 6/6] avconv: fix bitrate report when writing to /dev/null avio_size() reports the filesize which returns 0 for /dev/null. avio_tell() reports the current position. Also handle errors from avio_tell(). --- avconv.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/avconv.c b/avconv.c index bf1e2fac48..54a0e2a431 100644 --- a/avconv.c +++ b/avconv.c @@ -807,8 +807,15 @@ static void print_report(int is_last_report, int64_t timer_start) oc = output_files[0]->ctx; total_size = avio_size(oc->pb); - if (total_size < 0) // FIXME improve avio_size() so it works with non seekable output too + if (total_size <= 0) // FIXME improve avio_size() so it works with non seekable output too total_size = avio_tell(oc->pb); + if (total_size < 0) { + char errbuf[128]; + av_strerror(total_size, errbuf, sizeof(errbuf)); + av_log(NULL, AV_LOG_VERBOSE, "Bitrate not available, " + "avio_tell() failed: %s\n", errbuf); + total_size = 0; + } buf[0] = '\0'; ti1 = 1e10;