From 838b849e70f11dc242399da8d19c5795fe90913b Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Mon, 7 Jan 2013 18:54:50 +0100 Subject: [PATCH 1/3] v4l2: set the average framerate instead of codec timebase. Codec timebase is supposed to be set by decoders only. --- libavdevice/v4l2.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libavdevice/v4l2.c b/libavdevice/v4l2.c index fd2ab385c0..eb5de151f3 100644 --- a/libavdevice/v4l2.c +++ b/libavdevice/v4l2.c @@ -634,11 +634,11 @@ static int v4l2_set_parameters(AVFormatContext *s1) return AVERROR(errno); } } - s1->streams[0]->codec->time_base.den = tpf->denominator; - s1->streams[0]->codec->time_base.num = tpf->numerator; + s1->streams[0]->avg_frame_rate.num = tpf->denominator; + s1->streams[0]->avg_frame_rate.den = tpf->numerator; s->timeout = 100 + - av_rescale_q(1, s1->streams[0]->codec->time_base, + av_rescale_q(1, s1->streams[0]->avg_frame_rate, (AVRational){1, 1000}); return 0; @@ -779,7 +779,7 @@ static int v4l2_read_header(AVFormatContext *s1) avcodec_pix_fmt_to_codec_tag(st->codec->pix_fmt); st->codec->width = s->width; st->codec->height = s->height; - st->codec->bit_rate = s->frame_size * 1/av_q2d(st->codec->time_base) * 8; + st->codec->bit_rate = s->frame_size * av_q2d(st->avg_frame_rate) * 8; return 0; } From 49dc82eef776634ac2da41fca9f105df25129ad8 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Tue, 8 Jan 2013 08:04:59 +0100 Subject: [PATCH 2/3] v4l2: do not assert on a value received from outside of Libav --- libavdevice/v4l2.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/libavdevice/v4l2.c b/libavdevice/v4l2.c index eb5de151f3..d57bd755d5 100644 --- a/libavdevice/v4l2.c +++ b/libavdevice/v4l2.c @@ -460,7 +460,12 @@ static int mmap_read_frame(AVFormatContext *ctx, AVPacket *pkt) return AVERROR(errno); } - assert (buf.index < s->buffers); + + if (buf.index >= s->buffers) { + av_log(ctx, AV_LOG_ERROR, "Invalid buffer index received.\n"); + return AVERROR(EINVAL); + } + if (s->frame_size > 0 && buf.bytesused != s->frame_size) { av_log(ctx, AV_LOG_ERROR, "The v4l2 frame is %d bytes, but %d bytes are expected\n", From 90cfc084e3e6d37ab88fc96a95f0401d8e8b4cd1 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Wed, 31 Oct 2012 06:42:08 +0100 Subject: [PATCH 3/3] avpacket: free side data in av_free_packet(). Freeing it in av_destruct_packet(), as is done currently, would mean that we allow it to be allocated with other means. But that would make av_packet_new_side_data() unsafe. Side data is not expected to be large, so copying it if required shouldn't be a problem. --- libavcodec/avpacket.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/libavcodec/avpacket.c b/libavcodec/avpacket.c index cb24948a48..c26fb8e35c 100644 --- a/libavcodec/avpacket.c +++ b/libavcodec/avpacket.c @@ -27,16 +27,9 @@ void av_destruct_packet(AVPacket *pkt) { - int i; - av_free(pkt->data); pkt->data = NULL; pkt->size = 0; - - for (i = 0; i < pkt->side_data_elems; i++) - av_free(pkt->side_data[i].data); - av_freep(&pkt->side_data); - pkt->side_data_elems = 0; } void av_init_packet(AVPacket *pkt) @@ -153,11 +146,16 @@ failed_alloc: void av_free_packet(AVPacket *pkt) { if (pkt) { + int i; + if (pkt->destruct) pkt->destruct(pkt); pkt->data = NULL; pkt->size = 0; - pkt->side_data = NULL; + + for (i = 0; i < pkt->side_data_elems; i++) + av_free(pkt->side_data[i].data); + av_freep(&pkt->side_data); pkt->side_data_elems = 0; } }