From 40a5dd2f35e0cfcfb92475a8f305fb6f78038507 Mon Sep 17 00:00:00 2001 From: Alex Converse Date: Wed, 25 May 2011 17:03:12 -0700 Subject: [PATCH 01/29] id3v2: Initialize tflags for version 2.2. --- libavformat/id3v2.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavformat/id3v2.c b/libavformat/id3v2.c index 4fecffe6ba..948261ad97 100644 --- a/libavformat/id3v2.c +++ b/libavformat/id3v2.c @@ -220,7 +220,7 @@ static void ff_id3v2_parse(AVFormatContext *s, int len, uint8_t version, uint8_t avio_skip(s->pb, get_size(s->pb, 4)); while (len >= taghdrlen) { - unsigned int tflags; + unsigned int tflags = 0; int tunsync = 0; if (isv34) { From 86f868771bac89168086285b71186fd8cf934cc3 Mon Sep 17 00:00:00 2001 From: Alex Converse Date: Wed, 25 May 2011 17:57:33 -0700 Subject: [PATCH 02/29] id3v2: Check malloc result. ID3v2 tags can be very large. --- libavformat/id3v2.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/libavformat/id3v2.c b/libavformat/id3v2.c index 948261ad97..06ae6f8b90 100644 --- a/libavformat/id3v2.c +++ b/libavformat/id3v2.c @@ -237,7 +237,7 @@ static void ff_id3v2_parse(AVFormatContext *s, int len, uint8_t version, uint8_t tag[3] = 0; tlen = avio_rb24(s->pb); } - if (tlen < 0 || tlen > len - taghdrlen) { + if (tlen <= 0 || tlen > len - taghdrlen) { av_log(s, AV_LOG_WARNING, "Invalid size in frame %s, skipping the rest of tag.\n", tag); break; } @@ -256,6 +256,10 @@ static void ff_id3v2_parse(AVFormatContext *s, int len, uint8_t version, uint8_t if (unsync || tunsync) { int i, j; av_fast_malloc(&buffer, &buffer_size, tlen); + if (!buffer) { + av_log(s, AV_LOG_ERROR, "Failed to alloc %d bytes\n", tlen); + goto seek; + } for (i = 0, j = 0; i < tlen; i++, j++) { buffer[j] = avio_r8(s->pb); if (j > 0 && !buffer[j] && buffer[j - 1] == 0xff) { @@ -276,6 +280,7 @@ static void ff_id3v2_parse(AVFormatContext *s, int len, uint8_t version, uint8_t break; } /* Skip to end of tag */ +seek: avio_seek(s->pb, next, SEEK_SET); } From 3577416212d992f63352f3695c6eb1b63567503d Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Thu, 26 May 2011 20:14:53 +0200 Subject: [PATCH 03/29] bktr: factorize returning error codes. This will be useful in the following commit. --- libavdevice/bktr.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/libavdevice/bktr.c b/libavdevice/bktr.c index 821567199e..810bdd67b9 100644 --- a/libavdevice/bktr.c +++ b/libavdevice/bktr.c @@ -249,9 +249,12 @@ static int grab_read_header(AVFormatContext *s1, AVFormatParameters *ap) int width, height; int frame_rate; int frame_rate_base; + int ret = 0; - if (ap->width <= 0 || ap->height <= 0 || ap->time_base.den <= 0) - return -1; + if (ap->width <= 0 || ap->height <= 0 || ap->time_base.den <= 0) { + ret = AVERROR(EINVAL); + goto out; + } width = ap->width; height = ap->height; @@ -259,8 +262,10 @@ static int grab_read_header(AVFormatContext *s1, AVFormatParameters *ap) frame_rate_base = ap->time_base.num; st = av_new_stream(s1, 0); - if (!st) - return AVERROR(ENOMEM); + if (!st) { + ret = AVERROR(ENOMEM); + goto out; + } av_set_pts_info(st, 64, 1, 1000000); /* 64 bits pts in use */ s->width = width; @@ -289,13 +294,16 @@ static int grab_read_header(AVFormatContext *s1, AVFormatParameters *ap) #endif if (bktr_init(s1->filename, width, height, s->standard, - &(s->video_fd), &(s->tuner_fd), -1, 0.0) < 0) - return AVERROR(EIO); + &(s->video_fd), &(s->tuner_fd), -1, 0.0) < 0) { + ret = AVERROR(EIO); + goto out; + } nsignals = 0; last_frame_time = 0; - return 0; +out: + return ret; } static int grab_read_close(AVFormatContext *s1) From 33e036967253b83621f378a75d3e4ed199bf4508 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Tue, 24 May 2011 07:43:01 +0200 Subject: [PATCH 04/29] bktr: add video_size private option. --- libavdevice/bktr.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/libavdevice/bktr.c b/libavdevice/bktr.c index 810bdd67b9..e8ff557b73 100644 --- a/libavdevice/bktr.c +++ b/libavdevice/bktr.c @@ -27,6 +27,7 @@ #include "libavformat/avformat.h" #include "libavutil/log.h" #include "libavutil/opt.h" +#include "libavutil/parseutils.h" #if HAVE_DEV_BKTR_IOCTL_METEOR_H && HAVE_DEV_BKTR_IOCTL_BT848_H # include # include @@ -57,6 +58,7 @@ typedef struct { int frame_rate_base; uint64_t per_frame; int standard; + char *video_size; /**< String describing video size, set by a private option. */ } VideoData; @@ -251,13 +253,21 @@ static int grab_read_header(AVFormatContext *s1, AVFormatParameters *ap) int frame_rate_base; int ret = 0; - if (ap->width <= 0 || ap->height <= 0 || ap->time_base.den <= 0) { + if (ap->time_base.den <= 0) { ret = AVERROR(EINVAL); goto out; } - width = ap->width; - height = ap->height; + if ((ret = av_parse_video_size(&width, &height, s->video_size)) < 0) { + av_log(s1, AV_LOG_ERROR, "Couldn't parse video size.\n"); + goto out; + } +#if FF_API_FORMAT_PARAMETERS + if (ap->width > 0) + width = ap->width; + if (ap->height > 0) + height = ap->height; +#endif frame_rate = ap->time_base.den; frame_rate_base = ap->time_base.num; @@ -303,6 +313,7 @@ static int grab_read_header(AVFormatContext *s1, AVFormatParameters *ap) last_frame_time = 0; out: + av_freep(&s->video_size); return ret; } @@ -324,6 +335,8 @@ static int grab_read_close(AVFormatContext *s1) return 0; } +#define OFFSET(x) offsetof(VideoData, x) +#define DEC AV_OPT_FLAG_DECODING_PARAM static const AVOption options[] = { { "standard", "", offsetof(VideoData, standard), FF_OPT_TYPE_INT, {.dbl = VIDEO_FORMAT}, PAL, NTSCJ, AV_OPT_FLAG_DECODING_PARAM, "standard" }, { "PAL", "", 0, FF_OPT_TYPE_CONST, {.dbl = PAL}, 0, 0, AV_OPT_FLAG_DECODING_PARAM, "standard" }, @@ -332,6 +345,7 @@ static const AVOption options[] = { { "PALN", "", 0, FF_OPT_TYPE_CONST, {.dbl = PALN}, 0, 0, AV_OPT_FLAG_DECODING_PARAM, "standard" }, { "PALM", "", 0, FF_OPT_TYPE_CONST, {.dbl = PALM}, 0, 0, AV_OPT_FLAG_DECODING_PARAM, "standard" }, { "NTSCJ", "", 0, FF_OPT_TYPE_CONST, {.dbl = NTSCJ}, 0, 0, AV_OPT_FLAG_DECODING_PARAM, "standard" }, + { "video_size", "A string describing frame size, such as 640x480 or hd720.", OFFSET(video_size), FF_OPT_TYPE_STRING, {.str = "vga"}, 0, 0, DEC }, { NULL }, }; From 284bac2e7770685831a8389e8f2eaae977d4daa4 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Thu, 26 May 2011 17:13:09 +0200 Subject: [PATCH 05/29] libdc1394: return meaninful error codes. --- libavdevice/libdc1394.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/libavdevice/libdc1394.c b/libavdevice/libdc1394.c index 336c465311..50fc033d42 100644 --- a/libavdevice/libdc1394.c +++ b/libavdevice/libdc1394.c @@ -116,6 +116,7 @@ static inline int dc1394_read_common(AVFormatContext *c, AVFormatParameters *ap, int width = !ap->width ? 320 : ap->width; int height = !ap->height ? 240 : ap->height; int frame_rate = !ap->time_base.num ? 30000 : av_rescale(1000, ap->time_base.den, ap->time_base.num); + int ret = 0; for (fmt = dc1394_frame_formats; fmt->width; fmt++) if (fmt->pix_fmt == pix_fmt && fmt->width == width && fmt->height == height) @@ -128,13 +129,16 @@ static inline int dc1394_read_common(AVFormatContext *c, AVFormatParameters *ap, if (!fps->frame_rate || !fmt->width) { av_log(c, AV_LOG_ERROR, "Can't find matching camera format for %s, %dx%d@%d:1000fps\n", avcodec_get_pix_fmt_name(pix_fmt), width, height, frame_rate); + ret = AVERROR(EINVAL); goto out; } /* create a video stream */ vst = av_new_stream(c, 0); - if (!vst) + if (!vst) { + ret = AVERROR(ENOMEM); goto out; + } av_set_pts_info(vst, 64, 1, 1000); vst->codec->codec_type = AVMEDIA_TYPE_VIDEO; vst->codec->codec_id = CODEC_ID_RAWVIDEO; @@ -156,9 +160,8 @@ static inline int dc1394_read_common(AVFormatContext *c, AVFormatParameters *ap, vst->codec->bit_rate = av_rescale(dc1394->packet.size * 8, fps->frame_rate, 1000); *select_fps = fps; *select_fmt = fmt; - return 0; out: - return -1; + return ret; } #if HAVE_LIBDC1394_1 From fd48620e3e259cdb8df9e7d677a943d6e7d3575b Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Tue, 24 May 2011 07:43:01 +0200 Subject: [PATCH 06/29] libdc1394: add video_size private option. --- libavdevice/libdc1394.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/libavdevice/libdc1394.c b/libavdevice/libdc1394.c index 50fc033d42..4462262c93 100644 --- a/libavdevice/libdc1394.c +++ b/libavdevice/libdc1394.c @@ -24,6 +24,7 @@ #include "libavformat/avformat.h" #include "libavutil/log.h" #include "libavutil/opt.h" +#include "libavutil/parseutils.h" #if HAVE_LIBDC1394_2 #include @@ -59,6 +60,7 @@ typedef struct dc1394_data { #endif int current_frame; int fps; + char *video_size; /**< String describing video size, set by a private option. */ AVPacket packet; } dc1394_data; @@ -90,10 +92,13 @@ struct dc1394_frame_rate { { 0, 0 } /* gotta be the last one */ }; +#define OFFSET(x) offsetof(dc1394_data, x) +#define DEC AV_OPT_FLAG_DECODING_PARAM static const AVOption options[] = { #if HAVE_LIBDC1394_1 { "channel", "", offsetof(dc1394_data, channel), FF_OPT_TYPE_INT, {.dbl = 0}, 0, INT_MAX, AV_OPT_FLAG_DECODING_PARAM }, #endif + { "video_size", "A string describing frame size, such as 640x480 or hd720.", OFFSET(video_size), FF_OPT_TYPE_STRING, {.str = "qvga"}, 0, 0, DEC }, { NULL }, }; @@ -113,11 +118,21 @@ static inline int dc1394_read_common(AVFormatContext *c, AVFormatParameters *ap, struct dc1394_frame_format *fmt; struct dc1394_frame_rate *fps; enum PixelFormat pix_fmt = ap->pix_fmt == PIX_FMT_NONE ? PIX_FMT_UYVY422 : ap->pix_fmt; /* defaults */ - int width = !ap->width ? 320 : ap->width; - int height = !ap->height ? 240 : ap->height; + int width, height; int frame_rate = !ap->time_base.num ? 30000 : av_rescale(1000, ap->time_base.den, ap->time_base.num); int ret = 0; + if ((ret = av_parse_video_size(&width, &height, dc1394->video_size)) < 0) { + av_log(c, AV_LOG_ERROR, "Couldn't parse video size.\n"); + goto out; + } +#if FF_API_FORMAT_PARAMETERS + if (ap->width > 0) + width = ap->width; + if (ap->height > 0) + height = ap->height; +#endif + for (fmt = dc1394_frame_formats; fmt->width; fmt++) if (fmt->pix_fmt == pix_fmt && fmt->width == width && fmt->height == height) break; @@ -161,6 +176,7 @@ static inline int dc1394_read_common(AVFormatContext *c, AVFormatParameters *ap, *select_fps = fps; *select_fmt = fmt; out: + av_freep(&dc1394->video_size); return ret; } From 82b5aa0add203e6e90e3bbefbb9eb02118256ff6 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Thu, 26 May 2011 20:37:08 +0200 Subject: [PATCH 07/29] v4l2: factorize returning error codes. This will be useful in the following commit. --- libavdevice/v4l2.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/libavdevice/v4l2.c b/libavdevice/v4l2.c index 566ee92801..30eb972bf5 100644 --- a/libavdevice/v4l2.c +++ b/libavdevice/v4l2.c @@ -577,13 +577,14 @@ static int v4l2_read_header(AVFormatContext *s1, AVFormatParameters *ap) { struct video_data *s = s1->priv_data; AVStream *st; - int res; + int res = 0; uint32_t desired_format, capabilities; enum CodecID codec_id; st = av_new_stream(s1, 0); if (!st) { - return AVERROR(ENOMEM); + res = AVERROR(ENOMEM); + goto out; } av_set_pts_info(st, 64, 1, 1000000); /* 64 bits pts in us */ @@ -593,7 +594,8 @@ static int v4l2_read_header(AVFormatContext *s1, AVFormatParameters *ap) capabilities = 0; s->fd = device_open(s1, &capabilities); if (s->fd < 0) { - return AVERROR(EIO); + res = AVERROR(EIO); + goto out; } av_log(s1, AV_LOG_VERBOSE, "[%d]Capabilities: %x\n", s->fd, capabilities); @@ -604,7 +606,8 @@ static int v4l2_read_header(AVFormatContext *s1, AVFormatParameters *ap) fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; if (ioctl(s->fd, VIDIOC_G_FMT, &fmt) < 0) { av_log(s1, AV_LOG_ERROR, "ioctl(VIDIOC_G_FMT): %s\n", strerror(errno)); - return AVERROR(errno); + res = AVERROR(errno); + goto out; } s->width = fmt.fmt.pix.width; s->height = fmt.fmt.pix.height; @@ -617,14 +620,15 @@ static int v4l2_read_header(AVFormatContext *s1, AVFormatParameters *ap) "codec_id %d, pix_fmt %d.\n", s1->video_codec_id, ap->pix_fmt); close(s->fd); - return AVERROR(EIO); + res = AVERROR(EIO); + goto out; } - if (av_image_check_size(s->width, s->height, 0, s1) < 0) - return AVERROR(EINVAL); + if ((res = av_image_check_size(s->width, s->height, 0, s1) < 0)) + goto out; s->frame_format = desired_format; - if (v4l2_set_parameters(s1, ap) < 0) - return AVERROR(EIO); + if ((res = v4l2_set_parameters(s1, ap) < 0)) + goto out; st->codec->pix_fmt = fmt_v4l2ff(desired_format, codec_id); s->frame_size = avpicture_get_size(st->codec->pix_fmt, s->width, s->height); @@ -641,7 +645,8 @@ static int v4l2_read_header(AVFormatContext *s1, AVFormatParameters *ap) if (res < 0) { close(s->fd); - return AVERROR(EIO); + res = AVERROR(EIO); + goto out; } s->top_field_first = first_field(s->fd); @@ -653,7 +658,8 @@ static int v4l2_read_header(AVFormatContext *s1, AVFormatParameters *ap) st->codec->time_base.num = ap->time_base.num; st->codec->bit_rate = s->frame_size * 1/av_q2d(st->codec->time_base) * 8; - return 0; +out: + return res; } static int v4l2_read_packet(AVFormatContext *s1, AVPacket *pkt) From 8fe7b6443fe8721215f1abac3b854cd52092c909 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Tue, 24 May 2011 07:43:01 +0200 Subject: [PATCH 08/29] v4l2: add video_size private option. --- libavdevice/v4l2.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/libavdevice/v4l2.c b/libavdevice/v4l2.c index 30eb972bf5..f5baf08b42 100644 --- a/libavdevice/v4l2.c +++ b/libavdevice/v4l2.c @@ -46,6 +46,7 @@ #include "libavutil/imgutils.h" #include "libavutil/log.h" #include "libavutil/opt.h" +#include "libavutil/parseutils.h" static const int desired_video_buffers = 256; @@ -69,6 +70,7 @@ struct video_data { unsigned int *buf_len; char *standard; int channel; + char *video_size; /**< String describing video size, set by a private option. */ }; struct buff_data { @@ -588,8 +590,16 @@ static int v4l2_read_header(AVFormatContext *s1, AVFormatParameters *ap) } av_set_pts_info(st, 64, 1, 1000000); /* 64 bits pts in us */ - s->width = ap->width; - s->height = ap->height; + if (s->video_size && (res = av_parse_video_size(&s->width, &s->height, s->video_size)) < 0) { + av_log(s1, AV_LOG_ERROR, "Couldn't parse video size.\n"); + goto out; + } +#if FF_API_FORMAT_PARAMETERS + if (ap->width > 0) + s->width = ap->width; + if (ap->height > 0) + s->height = ap->height; +#endif capabilities = 0; s->fd = device_open(s1, &capabilities); @@ -659,6 +669,7 @@ static int v4l2_read_header(AVFormatContext *s1, AVFormatParameters *ap) st->codec->bit_rate = s->frame_size * 1/av_q2d(st->codec->time_base) * 8; out: + av_freep(&s->video_size); return res; } @@ -702,9 +713,12 @@ static int v4l2_read_close(AVFormatContext *s1) return 0; } +#define OFFSET(x) offsetof(struct video_data, x) +#define DEC AV_OPT_FLAG_DECODING_PARAM static const AVOption options[] = { { "standard", "", offsetof(struct video_data, standard), FF_OPT_TYPE_STRING, {.str = "NTSC" }, 0, 0, AV_OPT_FLAG_DECODING_PARAM }, { "channel", "", offsetof(struct video_data, channel), FF_OPT_TYPE_INT, {.dbl = 0 }, 0, INT_MAX, AV_OPT_FLAG_DECODING_PARAM }, + { "video_size", "A string describing frame size, such as 640x480 or hd720.", OFFSET(video_size), FF_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC }, { NULL }, }; From 3e15ea21504a5cc1765afd78dd72ef486a10a27b Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Tue, 24 May 2011 07:43:01 +0200 Subject: [PATCH 09/29] vfwcap: add video_size private option. --- libavdevice/vfwcap.c | 46 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 38 insertions(+), 8 deletions(-) diff --git a/libavdevice/vfwcap.c b/libavdevice/vfwcap.c index 8eecf5bdff..d307e11184 100644 --- a/libavdevice/vfwcap.c +++ b/libavdevice/vfwcap.c @@ -20,6 +20,9 @@ */ #include "libavformat/avformat.h" +#include "libavutil/log.h" +#include "libavutil/opt.h" +#include "libavutil/parseutils.h" #include #include @@ -34,12 +37,14 @@ /* End of missing MinGW defines */ struct vfw_ctx { + const AVClass *class; HWND hwnd; HANDLE mutex; HANDLE event; AVPacketList *pktl; unsigned int curbufsize; unsigned int frame_num; + char *video_size; /**< A string describing video size, set by a private option. */ }; static enum PixelFormat vfw_pixfmt(DWORD biCompression, WORD biBitCount) @@ -230,6 +235,8 @@ static int vfw_read_close(AVFormatContext *s) pktl = next; } + av_freep(&ctx->video_size); + return 0; } @@ -244,8 +251,6 @@ static int vfw_read_header(AVFormatContext *s, AVFormatParameters *ap) CAPTUREPARMS cparms; DWORD biCompression; WORD biBitCount; - int width; - int height; int ret; if (!strcmp(s->filename, "list")) { @@ -318,10 +323,20 @@ static int vfw_read_header(AVFormatContext *s, AVFormatParameters *ap) dump_bih(s, &bi->bmiHeader); - width = ap->width ? ap->width : bi->bmiHeader.biWidth ; - height = ap->height ? ap->height : bi->bmiHeader.biHeight; - bi->bmiHeader.biWidth = width ; - bi->bmiHeader.biHeight = height; + + if (ctx->video_size) { + ret = av_parse_video_size(&bi->bmiHeader.biWidth, &bi->bmiHeader.biHeight, ctx->video_size); + if (ret < 0) { + av_log(s, AV_LOG_ERROR, "Couldn't parse video size.\n"); + goto fail_bi; + } + } +#if FF_API_FORMAT_PARAMETERS + if (ap->width > 0) + bi->bmiHeader.biWidth = ap->width; + if (ap->height > 0) + bi->bmiHeader.biHeight = ap->height; +#endif if (0) { /* For testing yet unsupported compressions @@ -370,8 +385,8 @@ static int vfw_read_header(AVFormatContext *s, AVFormatParameters *ap) codec = st->codec; codec->time_base = ap->time_base; codec->codec_type = AVMEDIA_TYPE_VIDEO; - codec->width = width; - codec->height = height; + codec->width = bi->bmiHeader.biWidth; + codec->height = bi->bmiHeader.biHeight; codec->pix_fmt = vfw_pixfmt(biCompression, biBitCount); if(codec->pix_fmt == PIX_FMT_NONE) { codec->codec_id = vfw_codecid(biCompression); @@ -452,6 +467,20 @@ static int vfw_read_packet(AVFormatContext *s, AVPacket *pkt) return pkt->size; } +#define OFFSET(x) offsetof(struct vfw_ctx, x) +#define DEC AV_OPT_FLAG_DECODING_PARAM +static const AVOption options[] = { + { "video_size", "A string describing frame size, such as 640x480 or hd720.", OFFSET(video_size), FF_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC }, + { NULL }, +}; + +static const AVClass vfw_class = { + .class_name = "VFW indev", + .item_name = av_default_item_name, + .option = options, + .version = LIBAVUTIL_VERSION_INT, +}; + AVInputFormat ff_vfwcap_demuxer = { "vfwcap", NULL_IF_CONFIG_SMALL("VFW video capture"), @@ -461,4 +490,5 @@ AVInputFormat ff_vfwcap_demuxer = { vfw_read_packet, vfw_read_close, .flags = AVFMT_NOFILE, + .priv_class = &vfw_class, }; From 3102fb0351fb9dd96543b3f1b9c4c04758226ee5 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Thu, 26 May 2011 21:17:05 +0200 Subject: [PATCH 10/29] x11grab: factorize returning error codes. --- libavdevice/x11grab.c | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/libavdevice/x11grab.c b/libavdevice/x11grab.c index 0e63d09fea..2e1f019584 100644 --- a/libavdevice/x11grab.c +++ b/libavdevice/x11grab.c @@ -91,6 +91,7 @@ x11grab_read_header(AVFormatContext *s1, AVFormatParameters *ap) int y_off = 0; int use_shm; char *param, *offset; + int ret = 0; param = av_strdup(s1->filename); offset = strchr(param, '+'); @@ -105,17 +106,20 @@ x11grab_read_header(AVFormatContext *s1, AVFormatParameters *ap) dpy = XOpenDisplay(param); if(!dpy) { av_log(s1, AV_LOG_ERROR, "Could not open X display.\n"); - return AVERROR(EIO); + ret = AVERROR(EIO); + goto out; } if (ap->width <= 0 || ap->height <= 0 || ap->time_base.den <= 0) { av_log(s1, AV_LOG_ERROR, "AVParameters don't have video size and/or rate. Use -s and -r.\n"); - return AVERROR(EIO); + ret = AVERROR(EINVAL); + goto out; } st = av_new_stream(s1, 0); if (!st) { - return AVERROR(ENOMEM); + ret = AVERROR(ENOMEM); + goto out; } av_set_pts_info(st, 64, 1, 1000000); /* 64 bits pts in us */ @@ -136,7 +140,8 @@ x11grab_read_header(AVFormatContext *s1, AVFormatParameters *ap) IPC_CREAT|0777); if (x11grab->shminfo.shmid == -1) { av_log(s1, AV_LOG_ERROR, "Fatal: Can't get shared memory!\n"); - return AVERROR(ENOMEM); + ret = AVERROR(ENOMEM); + goto out; } x11grab->shminfo.shmaddr = image->data = shmat(x11grab->shminfo.shmid, 0, 0); x11grab->shminfo.readOnly = False; @@ -144,7 +149,8 @@ x11grab_read_header(AVFormatContext *s1, AVFormatParameters *ap) if (!XShmAttach(dpy, &x11grab->shminfo)) { av_log(s1, AV_LOG_ERROR, "Fatal: Failed to attach shared memory!\n"); /* needs some better error subroutine :) */ - return AVERROR(EIO); + ret = AVERROR(EIO); + goto out; } } else { image = XGetImage(dpy, RootWindow(dpy, DefaultScreen(dpy)), @@ -172,7 +178,8 @@ x11grab_read_header(AVFormatContext *s1, AVFormatParameters *ap) } else { av_log(s1, AV_LOG_ERROR, "RGB ordering at image depth %i not supported ... aborting\n", image->bits_per_pixel); av_log(s1, AV_LOG_ERROR, "color masks: r 0x%.6lx g 0x%.6lx b 0x%.6lx\n", image->red_mask, image->green_mask, image->blue_mask); - return AVERROR(EIO); + ret = AVERROR(EIO); + goto out; } break; case 24: @@ -187,7 +194,8 @@ x11grab_read_header(AVFormatContext *s1, AVFormatParameters *ap) } else { av_log(s1, AV_LOG_ERROR,"rgb ordering at image depth %i not supported ... aborting\n", image->bits_per_pixel); av_log(s1, AV_LOG_ERROR, "color masks: r 0x%.6lx g 0x%.6lx b 0x%.6lx\n", image->red_mask, image->green_mask, image->blue_mask); - return AVERROR(EIO); + ret = AVERROR(EIO); + goto out; } break; case 32: @@ -210,7 +218,8 @@ x11grab_read_header(AVFormatContext *s1, AVFormatParameters *ap) break; default: av_log(s1, AV_LOG_ERROR, "image depth %i not supported ... aborting\n", image->bits_per_pixel); - return -1; + ret = AVERROR(EINVAL); + goto out; } x11grab->frame_size = ap->width * ap->height * image->bits_per_pixel/8; @@ -232,7 +241,8 @@ x11grab_read_header(AVFormatContext *s1, AVFormatParameters *ap) st->codec->time_base = ap->time_base; st->codec->bit_rate = x11grab->frame_size * 1/av_q2d(ap->time_base) * 8; - return 0; +out: + return ret; } /** From 724a900c454f7b41066edcc0443bff083d59f81c Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Tue, 24 May 2011 07:43:01 +0200 Subject: [PATCH 11/29] x11grab: add video_size private option. --- libavdevice/x11grab.c | 48 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 39 insertions(+), 9 deletions(-) diff --git a/libavdevice/x11grab.c b/libavdevice/x11grab.c index 2e1f019584..d4fcbca873 100644 --- a/libavdevice/x11grab.c +++ b/libavdevice/x11grab.c @@ -37,6 +37,9 @@ #include "config.h" #include "libavformat/avformat.h" +#include "libavutil/log.h" +#include "libavutil/opt.h" +#include "libavutil/parseutils.h" #include #include #include @@ -52,10 +55,12 @@ */ struct x11_grab { + const AVClass *class; /**< Class for private options. */ int frame_size; /**< Size in bytes of a grabbed frame */ AVRational time_base; /**< Time base */ int64_t time_frame; /**< Current time */ + char *video_size; /**< String describing video size, set by a private option. */ int height; /**< Height of the grab frame */ int width; /**< Width of the grab frame */ int x_off; /**< Horizontal top-left corner coordinate */ @@ -101,7 +106,18 @@ x11grab_read_header(AVFormatContext *s1, AVFormatParameters *ap) *offset= 0; } - av_log(s1, AV_LOG_INFO, "device: %s -> display: %s x: %d y: %d width: %d height: %d\n", s1->filename, param, x_off, y_off, ap->width, ap->height); + if ((ret = av_parse_video_size(&x11grab->width, &x11grab->height, x11grab->video_size)) < 0) { + av_log(s1, AV_LOG_ERROR, "Couldn't parse video size.\n"); + goto out; + } +#if FF_API_FORMAT_PARAMETERS + if (ap->width > 0) + x11grab->width = ap->width; + if (ap->height > 0) + x11grab->height = ap->height; +#endif + av_log(s1, AV_LOG_INFO, "device: %s -> display: %s x: %d y: %d width: %d height: %d\n", + s1->filename, param, x_off, y_off, x11grab->width, x11grab->height); dpy = XOpenDisplay(param); if(!dpy) { @@ -110,7 +126,7 @@ x11grab_read_header(AVFormatContext *s1, AVFormatParameters *ap) goto out; } - if (ap->width <= 0 || ap->height <= 0 || ap->time_base.den <= 0) { + if (ap->time_base.den <= 0) { av_log(s1, AV_LOG_ERROR, "AVParameters don't have video size and/or rate. Use -s and -r.\n"); ret = AVERROR(EINVAL); goto out; @@ -134,7 +150,7 @@ x11grab_read_header(AVFormatContext *s1, AVFormatParameters *ap) ZPixmap, NULL, &x11grab->shminfo, - ap->width, ap->height); + x11grab->width, x11grab->height); x11grab->shminfo.shmid = shmget(IPC_PRIVATE, image->bytes_per_line * image->height, IPC_CREAT|0777); @@ -155,7 +171,7 @@ x11grab_read_header(AVFormatContext *s1, AVFormatParameters *ap) } else { image = XGetImage(dpy, RootWindow(dpy, DefaultScreen(dpy)), x_off,y_off, - ap->width,ap->height, + x11grab->width, x11grab->height, AllPlanes, ZPixmap); } @@ -222,10 +238,8 @@ x11grab_read_header(AVFormatContext *s1, AVFormatParameters *ap) goto out; } - x11grab->frame_size = ap->width * ap->height * image->bits_per_pixel/8; + x11grab->frame_size = x11grab->width * x11grab->height * image->bits_per_pixel/8; x11grab->dpy = dpy; - x11grab->width = ap->width; - x11grab->height = ap->height; x11grab->time_base = ap->time_base; x11grab->time_frame = av_gettime() / av_q2d(ap->time_base); x11grab->x_off = x_off; @@ -235,13 +249,14 @@ x11grab_read_header(AVFormatContext *s1, AVFormatParameters *ap) st->codec->codec_type = AVMEDIA_TYPE_VIDEO; st->codec->codec_id = CODEC_ID_RAWVIDEO; - st->codec->width = ap->width; - st->codec->height = ap->height; + st->codec->width = x11grab->width; + st->codec->height = x11grab->height; st->codec->pix_fmt = input_pixfmt; st->codec->time_base = ap->time_base; st->codec->bit_rate = x11grab->frame_size * 1/av_q2d(ap->time_base) * 8; out: + av_freep(&x11grab->video_size); return ret; } @@ -449,6 +464,20 @@ x11grab_read_close(AVFormatContext *s1) return 0; } +#define OFFSET(x) offsetof(struct x11_grab, x) +#define DEC AV_OPT_FLAG_DECODING_PARAM +static const AVOption options[] = { + { "video_size", "A string describing frame size, such as 640x480 or hd720.", OFFSET(video_size), FF_OPT_TYPE_STRING, {.str = "vga"}, 0, 0, DEC }, + { NULL }, +}; + +static const AVClass x11_class = { + .class_name = "X11grab indev", + .item_name = av_default_item_name, + .option = options, + .version = LIBAVUTIL_VERSION_INT, +}; + /** x11 grabber device demuxer declaration */ AVInputFormat ff_x11_grab_device_demuxer = { @@ -460,4 +489,5 @@ AVInputFormat ff_x11_grab_device_demuxer = x11grab_read_packet, x11grab_read_close, .flags = AVFMT_NOFILE, + .priv_class = &x11_class, }; From 973f686a6c4f7c3b9120a1e22cb7c0159ea9aee2 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Tue, 24 May 2011 07:43:01 +0200 Subject: [PATCH 12/29] rawdec: add video_size private option. --- libavformat/rawdec.c | 40 ++++++++++++++++++++++++++++++++++++--- libavformat/rawdec.h | 6 ++++++ libavformat/rawvideodec.c | 3 ++- 3 files changed, 45 insertions(+), 4 deletions(-) diff --git a/libavformat/rawdec.c b/libavformat/rawdec.c index b545dbd6d7..265822b2da 100644 --- a/libavformat/rawdec.c +++ b/libavformat/rawdec.c @@ -24,6 +24,7 @@ #include "avio_internal.h" #include "rawdec.h" #include "libavutil/opt.h" +#include "libavutil/parseutils.h" /* raw input */ int ff_raw_read_header(AVFormatContext *s, AVFormatParameters *ap) @@ -66,17 +67,34 @@ int ff_raw_read_header(AVFormatContext *s, AVFormatParameters *ap) av_set_pts_info(st, 64, 1, st->codec->sample_rate); break; } - case AVMEDIA_TYPE_VIDEO: + case AVMEDIA_TYPE_VIDEO: { + FFRawVideoDemuxerContext *s1 = s->priv_data; + int width = 0, height = 0, ret; if(ap->time_base.num) av_set_pts_info(st, 64, ap->time_base.num, ap->time_base.den); else av_set_pts_info(st, 64, 1, 25); - st->codec->width = ap->width; - st->codec->height = ap->height; + if (s1->video_size) { + ret = av_parse_video_size(&width, &height, s1->video_size); + av_freep(&s1->video_size); + if (ret < 0) { + av_log(s, AV_LOG_ERROR, "Couldn't parse video size.\n"); + return ret; + } + } +#if FF_API_FORMAT_PARAMETERS + if (ap->width > 0) + width = ap->width; + if (ap->height > 0) + height = ap->height; +#endif + st->codec->width = width; + st->codec->height = height; st->codec->pix_fmt = ap->pix_fmt; if(st->codec->pix_fmt == PIX_FMT_NONE) st->codec->pix_fmt= PIX_FMT_YUV420P; break; + } default: return -1; } @@ -165,6 +183,22 @@ const AVClass ff_rawaudio_demuxer_class = { .version = LIBAVUTIL_VERSION_INT, }; +#define OFFSET(x) offsetof(FFRawVideoDemuxerContext, x) +#define DEC AV_OPT_FLAG_DECODING_PARAM +static const AVOption video_options[] = { + { "video_size", "A string describing frame size, such as 640x480 or hd720.", OFFSET(video_size), FF_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC }, + { NULL }, +}; +#undef OFFSET +#undef DEC + +const AVClass ff_rawvideo_demuxer_class = { + .class_name = "rawvideo demuxer", + .item_name = av_default_item_name, + .option = video_options, + .version = LIBAVUTIL_VERSION_INT, +}; + #if CONFIG_G722_DEMUXER AVInputFormat ff_g722_demuxer = { "g722", diff --git a/libavformat/rawdec.h b/libavformat/rawdec.h index e473eb2aac..517efd4042 100644 --- a/libavformat/rawdec.h +++ b/libavformat/rawdec.h @@ -31,7 +31,13 @@ typedef struct RawAudioDemuxerContext { 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. */ +} FFRawVideoDemuxerContext; + extern const AVClass ff_rawaudio_demuxer_class; +extern const AVClass ff_rawvideo_demuxer_class; int ff_raw_read_header(AVFormatContext *s, AVFormatParameters *ap); diff --git a/libavformat/rawvideodec.c b/libavformat/rawvideodec.c index a29f7da7a4..f8d9b65f36 100644 --- a/libavformat/rawvideodec.c +++ b/libavformat/rawvideodec.c @@ -47,11 +47,12 @@ static int rawvideo_read_packet(AVFormatContext *s, AVPacket *pkt) AVInputFormat ff_rawvideo_demuxer = { "rawvideo", NULL_IF_CONFIG_SMALL("raw video format"), - 0, + sizeof(FFRawVideoDemuxerContext), NULL, ff_raw_read_header, rawvideo_read_packet, .flags= AVFMT_GENERIC_INDEX, .extensions = "yuv,cif,qcif,rgb", .value = CODEC_ID_RAWVIDEO, + .priv_class = &ff_rawvideo_demuxer_class, }; From 06d8c9e5f0d9db605830d36678ccefeceddce610 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Tue, 24 May 2011 07:43:01 +0200 Subject: [PATCH 13/29] tty: add video_size private option. --- libavformat/tty.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/libavformat/tty.c b/libavformat/tty.c index bc6058d857..432fcc0c3d 100644 --- a/libavformat/tty.c +++ b/libavformat/tty.c @@ -28,6 +28,7 @@ #include "libavutil/avstring.h" #include "libavutil/log.h" #include "libavutil/opt.h" +#include "libavutil/parseutils.h" #include "avformat.h" #include "sauce.h" @@ -35,6 +36,7 @@ typedef struct { AVClass *class; int chars_per_frame; uint64_t fsize; /**< file size less metadata buffer */ + char *video_size;/**< A string describing video size, set by a private option. */ } TtyDemuxContext; /** @@ -71,14 +73,30 @@ static int read_header(AVFormatContext *avctx, AVFormatParameters *ap) { TtyDemuxContext *s = avctx->priv_data; + int width = 0, height = 0, ret; AVStream *st = av_new_stream(avctx, 0); if (!st) return AVERROR(ENOMEM); st->codec->codec_tag = 0; st->codec->codec_type = AVMEDIA_TYPE_VIDEO; st->codec->codec_id = CODEC_ID_ANSI; - if (ap->width) st->codec->width = ap->width; - if (ap->height) st->codec->height = ap->height; + + if (s->video_size) { + ret = av_parse_video_size(&width, &height, s->video_size); + av_freep(&s->video_size); + if (ret < 0) { + av_log (avctx, AV_LOG_ERROR, "Couldn't parse video size.\n"); + return ret; + } + } +#if FF_API_FORMAT_PARAMETERS + if (ap->width > 0) + width = ap->width; + if (ap->height > 0) + height = ap->height; +#endif + st->codec->width = width; + st->codec->height = height; if (!ap->time_base.num) { av_set_pts_info(st, 60, 1, 25); @@ -129,8 +147,11 @@ static int read_packet(AVFormatContext *avctx, AVPacket *pkt) return 0; } +#define OFFSET(x) offsetof(TtyDemuxContext, x) +#define DEC AV_OPT_FLAG_DECODING_PARAM static const AVOption options[] = { { "chars_per_frame", "", offsetof(TtyDemuxContext, chars_per_frame), FF_OPT_TYPE_INT, {.dbl = 6000}, 1, INT_MAX, AV_OPT_FLAG_DECODING_PARAM}, + { "video_size", "A string describing frame size, such as 640x480 or hd720.", OFFSET(video_size), FF_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC }, { NULL }, }; From 89d1b7f40671e0d455fe6b6670bf6f2bcf2eea2e Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Thu, 26 May 2011 08:14:03 +0200 Subject: [PATCH 14/29] lavf: deprecate AVFormatParameters.width/height. --- libavformat/avformat.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libavformat/avformat.h b/libavformat/avformat.h index 3a652a354b..847e408641 100644 --- a/libavformat/avformat.h +++ b/libavformat/avformat.h @@ -231,9 +231,9 @@ typedef struct AVFormatParameters { #if FF_API_FORMAT_PARAMETERS attribute_deprecated int sample_rate; attribute_deprecated int channels; + attribute_deprecated int width; + attribute_deprecated int height; #endif - int width; - int height; enum PixelFormat pix_fmt; #if FF_API_FORMAT_PARAMETERS attribute_deprecated int channel; /**< Used to select DV channel. */ From 4779f59378d54f30644ef79ce3a5c402546f3cb9 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Tue, 24 May 2011 08:44:10 +0200 Subject: [PATCH 15/29] rtspdec: add initial_pause private option. Deprecate corresponding AVFormatParameters field. --- libavformat/avformat.h | 4 ++-- libavformat/rtsp.h | 8 ++++++++ libavformat/rtspdec.c | 21 ++++++++++++++++++++- 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/libavformat/avformat.h b/libavformat/avformat.h index 847e408641..2ea940c186 100644 --- a/libavformat/avformat.h +++ b/libavformat/avformat.h @@ -241,9 +241,9 @@ typedef struct AVFormatParameters { attribute_deprecated unsigned int mpeg2ts_raw:1; /**< deprecated, use mpegtsraw demuxer */ /**< deprecated, use mpegtsraw demuxer-specific options instead */ attribute_deprecated unsigned int mpeg2ts_compute_pcr:1; + attribute_deprecated unsigned int initial_pause:1; /**< Do not begin to play the stream + immediately (RTSP only). */ #endif - unsigned int initial_pause:1; /**< Do not begin to play the stream - immediately (RTSP only). */ unsigned int prealloced_context:1; } AVFormatParameters; diff --git a/libavformat/rtsp.h b/libavformat/rtsp.h index ff66502626..f5a7fada21 100644 --- a/libavformat/rtsp.h +++ b/libavformat/rtsp.h @@ -28,6 +28,8 @@ #include "network.h" #include "httpauth.h" +#include "libavutil/log.h" + /** * Network layer over which RTP/etc packet data will be transported. */ @@ -196,6 +198,7 @@ enum RTSPServerType { * @todo Use AVIOContext instead of URLContext */ typedef struct RTSPState { + const AVClass *class; /**< Class for private options. */ URLContext *rtsp_hd; /* RTSP TCP connection handle */ /** number of items in the 'rtsp_streams' variable */ @@ -336,6 +339,11 @@ typedef struct RTSPState { * Whether the server supports the GET_PARAMETER method. */ int get_parameter_supported; + + /** + * Do not begin to play the stream immediately. + */ + int initial_pause; } RTSPState; /** diff --git a/libavformat/rtspdec.c b/libavformat/rtspdec.c index ccfc4d8e27..fa6bc05517 100644 --- a/libavformat/rtspdec.c +++ b/libavformat/rtspdec.c @@ -21,6 +21,7 @@ #include "libavutil/avstring.h" #include "libavutil/intreadwrite.h" +#include "libavutil/opt.h" #include "avformat.h" #include "internal.h" @@ -165,7 +166,12 @@ static int rtsp_read_header(AVFormatContext *s, return AVERROR(ENOMEM); rt->real_setup = rt->real_setup_cache + s->nb_streams; - if (ap->initial_pause) { +#if FF_API_FORMAT_PARAMETERS + if (ap->initial_pause) + rt->initial_pause = ap->initial_pause; +#endif + + if (rt->initial_pause) { /* do not start immediately */ } else { if (rtsp_read_play(s) < 0) { @@ -399,6 +405,18 @@ static int rtsp_read_close(AVFormatContext *s) return 0; } +static const AVOption options[] = { + { "initial_pause", "Don't start playing the stream immediately", offsetof(RTSPState, initial_pause), FF_OPT_TYPE_INT, {.dbl = 0}, 0, 1, AV_OPT_FLAG_DECODING_PARAM }, + { NULL }, +}; + +const AVClass rtsp_demuxer_class = { + .class_name = "RTSP demuxer", + .item_name = av_default_item_name, + .option = options, + .version = LIBAVUTIL_VERSION_INT, +}; + AVInputFormat ff_rtsp_demuxer = { "rtsp", NULL_IF_CONFIG_SMALL("RTSP input format"), @@ -411,4 +429,5 @@ AVInputFormat ff_rtsp_demuxer = { .flags = AVFMT_NOFILE, .read_play = rtsp_read_play, .read_pause = rtsp_read_pause, + .priv_class = &rtsp_demuxer_class, }; From fa4924a35818b2564050119ed7c14cbdd2b56065 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Wed, 25 May 2011 08:14:13 +0200 Subject: [PATCH 16/29] rawdec: factor video demuxer definitions into a macro. --- libavformat/cavsvideodec.c | 11 +---------- libavformat/diracdec.c | 11 +---------- libavformat/dnxhddec.c | 11 +---------- libavformat/h261dec.c | 12 +----------- libavformat/h263dec.c | 12 +----------- libavformat/h264dec.c | 12 +----------- libavformat/m4vdec.c | 12 +----------- libavformat/mpegvideodec.c | 11 +---------- libavformat/rawdec.c | 23 ++--------------------- libavformat/rawdec.h | 12 ++++++++++++ 10 files changed, 22 insertions(+), 105 deletions(-) diff --git a/libavformat/cavsvideodec.c b/libavformat/cavsvideodec.c index f58c56f6b6..9aa9413f4c 100644 --- a/libavformat/cavsvideodec.c +++ b/libavformat/cavsvideodec.c @@ -65,13 +65,4 @@ static int cavsvideo_probe(AVProbeData *p) return 0; } -AVInputFormat ff_cavsvideo_demuxer = { - "cavsvideo", - NULL_IF_CONFIG_SMALL("raw Chinese AVS video"), - 0, - cavsvideo_probe, - ff_raw_video_read_header, - ff_raw_read_partial_packet, - .flags= AVFMT_GENERIC_INDEX, - .value = CODEC_ID_CAVS, -}; +FF_DEF_RAWVIDEO_DEMUXER(cavsvideo, "raw Chinese AVS video", cavsvideo_probe, NULL, CODEC_ID_CAVS) diff --git a/libavformat/diracdec.c b/libavformat/diracdec.c index b0cb3bfc25..8cbd5b5146 100644 --- a/libavformat/diracdec.c +++ b/libavformat/diracdec.c @@ -31,13 +31,4 @@ static int dirac_probe(AVProbeData *p) return 0; } -AVInputFormat ff_dirac_demuxer = { - "dirac", - NULL_IF_CONFIG_SMALL("raw Dirac"), - 0, - dirac_probe, - ff_raw_video_read_header, - ff_raw_read_partial_packet, - .flags= AVFMT_GENERIC_INDEX, - .value = CODEC_ID_DIRAC, -}; +FF_DEF_RAWVIDEO_DEMUXER(dirac, "raw Dirac", dirac_probe, NULL, CODEC_ID_DIRAC) diff --git a/libavformat/dnxhddec.c b/libavformat/dnxhddec.c index df5d2e3867..2aa8017ad4 100644 --- a/libavformat/dnxhddec.c +++ b/libavformat/dnxhddec.c @@ -42,13 +42,4 @@ static int dnxhd_probe(AVProbeData *p) return AVPROBE_SCORE_MAX; } -AVInputFormat ff_dnxhd_demuxer = { - "dnxhd", - NULL_IF_CONFIG_SMALL("raw DNxHD (SMPTE VC-3)"), - 0, - dnxhd_probe, - ff_raw_video_read_header, - ff_raw_read_partial_packet, - .flags= AVFMT_GENERIC_INDEX, - .value = CODEC_ID_DNXHD, -}; +FF_DEF_RAWVIDEO_DEMUXER(dnxhd, "raw DNxHD (SMPTE VC-3)", dnxhd_probe, NULL, CODEC_ID_DNXHD) diff --git a/libavformat/h261dec.c b/libavformat/h261dec.c index 8d9c5fa8e5..1b416d4fc7 100644 --- a/libavformat/h261dec.c +++ b/libavformat/h261dec.c @@ -62,14 +62,4 @@ static int h261_probe(AVProbeData *p) return 0; } -AVInputFormat ff_h261_demuxer = { - "h261", - NULL_IF_CONFIG_SMALL("raw H.261"), - 0, - h261_probe, - ff_raw_video_read_header, - ff_raw_read_partial_packet, - .flags= AVFMT_GENERIC_INDEX, - .extensions = "h261", - .value = CODEC_ID_H261, -}; +FF_DEF_RAWVIDEO_DEMUXER(h261, "raw H.261", h261_probe, "h261", CODEC_ID_H261) diff --git a/libavformat/h263dec.c b/libavformat/h263dec.c index 5eda7afd60..b9185cbcb6 100644 --- a/libavformat/h263dec.c +++ b/libavformat/h263dec.c @@ -64,14 +64,4 @@ static int h263_probe(AVProbeData *p) return 0; } -AVInputFormat ff_h263_demuxer = { - "h263", - NULL_IF_CONFIG_SMALL("raw H.263"), - 0, - h263_probe, - ff_raw_video_read_header, - ff_raw_read_partial_packet, - .flags= AVFMT_GENERIC_INDEX, -// .extensions = "h263", //FIXME remove after writing mpeg4_probe - .value = CODEC_ID_H263, -}; +FF_DEF_RAWVIDEO_DEMUXER(h263, "raw H.263", h263_probe, NULL, CODEC_ID_H263) diff --git a/libavformat/h264dec.c b/libavformat/h264dec.c index 268492cf8d..f9086476d5 100644 --- a/libavformat/h264dec.c +++ b/libavformat/h264dec.c @@ -67,14 +67,4 @@ static int h264_probe(AVProbeData *p) return 0; } -AVInputFormat ff_h264_demuxer = { - "h264", - NULL_IF_CONFIG_SMALL("raw H.264 video format"), - 0, - h264_probe, - ff_raw_video_read_header, - ff_raw_read_partial_packet, - .flags= AVFMT_GENERIC_INDEX, - .extensions = "h26l,h264,264", //FIXME remove after writing mpeg4_probe - .value = CODEC_ID_H264, -}; +FF_DEF_RAWVIDEO_DEMUXER(h264 , "raw H.264 video format", h264_probe, "h26l,h264,264", CODEC_ID_H264) diff --git a/libavformat/m4vdec.c b/libavformat/m4vdec.c index 3463901d7b..e856aadc10 100644 --- a/libavformat/m4vdec.c +++ b/libavformat/m4vdec.c @@ -49,14 +49,4 @@ static int mpeg4video_probe(AVProbeData *probe_packet) return 0; } -AVInputFormat ff_m4v_demuxer = { - "m4v", - NULL_IF_CONFIG_SMALL("raw MPEG-4 video format"), - 0, - mpeg4video_probe, /** probing for MPEG-4 data */ - ff_raw_video_read_header, - ff_raw_read_partial_packet, - .flags= AVFMT_GENERIC_INDEX, - .extensions = "m4v", - .value = CODEC_ID_MPEG4, -}; +FF_DEF_RAWVIDEO_DEMUXER(m4v, "raw MPEG-4 video format", mpeg4video_probe, "m4v", CODEC_ID_MPEG4) diff --git a/libavformat/mpegvideodec.c b/libavformat/mpegvideodec.c index 0669820380..9fea117632 100644 --- a/libavformat/mpegvideodec.c +++ b/libavformat/mpegvideodec.c @@ -55,13 +55,4 @@ static int mpegvideo_probe(AVProbeData *p) return 0; } -AVInputFormat ff_mpegvideo_demuxer = { - "mpegvideo", - NULL_IF_CONFIG_SMALL("raw MPEG video"), - 0, - mpegvideo_probe, - ff_raw_video_read_header, - ff_raw_read_partial_packet, - .flags= AVFMT_GENERIC_INDEX, - .value = CODEC_ID_MPEG1VIDEO, -}; +FF_DEF_RAWVIDEO_DEMUXER(mpegvideo, "raw MPEG video", mpegvideo_probe, NULL, CODEC_ID_MPEG1VIDEO) diff --git a/libavformat/rawdec.c b/libavformat/rawdec.c index 265822b2da..434ed48f05 100644 --- a/libavformat/rawdec.c +++ b/libavformat/rawdec.c @@ -229,17 +229,7 @@ AVInputFormat ff_gsm_demuxer = { #endif #if CONFIG_MJPEG_DEMUXER -AVInputFormat ff_mjpeg_demuxer = { - "mjpeg", - NULL_IF_CONFIG_SMALL("raw MJPEG video"), - 0, - NULL, - ff_raw_video_read_header, - ff_raw_read_partial_packet, - .flags= AVFMT_GENERIC_INDEX, - .extensions = "mjpg,mjpeg", - .value = CODEC_ID_MJPEG, -}; +FF_DEF_RAWVIDEO_DEMUXER(mjpeg, "raw MJPEG video", NULL, "mjpg,mjpeg", CODEC_ID_MJPEG) #endif #if CONFIG_MLP_DEMUXER @@ -285,14 +275,5 @@ AVInputFormat ff_shorten_demuxer = { #endif #if CONFIG_VC1_DEMUXER -AVInputFormat ff_vc1_demuxer = { - "vc1", - NULL_IF_CONFIG_SMALL("raw VC-1"), - 0, - NULL /* vc1_probe */, - ff_raw_video_read_header, - ff_raw_read_partial_packet, - .extensions = "vc1", - .value = CODEC_ID_VC1, -}; +FF_DEF_RAWVIDEO_DEMUXER(vc1, "raw VC-1", NULL, "vc1", CODEC_ID_VC1) #endif diff --git a/libavformat/rawdec.h b/libavformat/rawdec.h index 517efd4042..99beadd0e1 100644 --- a/libavformat/rawdec.h +++ b/libavformat/rawdec.h @@ -47,4 +47,16 @@ int ff_raw_audio_read_header(AVFormatContext *s, AVFormatParameters *ap); int ff_raw_video_read_header(AVFormatContext *s, AVFormatParameters *ap); +#define FF_DEF_RAWVIDEO_DEMUXER(shortname, longname, probe, ext, id)\ +AVInputFormat ff_ ## shortname ## _demuxer = {\ + .name = #shortname,\ + .long_name = NULL_IF_CONFIG_SMALL(longname),\ + .read_probe = probe,\ + .read_header = ff_raw_video_read_header,\ + .read_packet = ff_raw_read_partial_packet,\ + .extensions = ext,\ + .flags = AVFMT_GENERIC_INDEX,\ + .value = id,\ +}; + #endif /* AVFORMAT_RAWDEC_H */ From ebb6b27ad9a72de2382a4eb438a11043273c4cad Mon Sep 17 00:00:00 2001 From: Luca Barbato Date: Fri, 20 May 2011 14:09:21 +0200 Subject: [PATCH 17/29] tcp: make connect() timeout properly The connect() timeout can take minutes, gets misreported as EIO and isn't interruptible. --- libavformat/tcp.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/libavformat/tcp.c b/libavformat/tcp.c index ced103876f..e602a556d2 100644 --- a/libavformat/tcp.c +++ b/libavformat/tcp.c @@ -45,6 +45,7 @@ static int tcp_open(URLContext *h, const char *uri, int flags) char buf[256]; int ret; socklen_t optlen; + int timeout = 100; char hostname[1024],proto[1024],path[1024]; char portstr[10]; @@ -57,6 +58,9 @@ static int tcp_open(URLContext *h, const char *uri, int flags) if (p) { if (av_find_info_tag(buf, sizeof(buf), "listen", p)) listen_socket = 1; + if (av_find_info_tag(buf, sizeof(buf), "timeout", p)) { + timeout = strtol(buf, NULL, 10); + } } memset(&hints, 0, sizeof(hints)); hints.ai_family = AF_UNSPEC; @@ -73,6 +77,7 @@ static int tcp_open(URLContext *h, const char *uri, int flags) cur_ai = ai; restart: + ret = AVERROR(EIO); fd = socket(cur_ai->ai_family, cur_ai->ai_socktype, cur_ai->ai_protocol); if (fd < 0) goto fail; @@ -84,28 +89,29 @@ static int tcp_open(URLContext *h, const char *uri, int flags) fd1 = accept(fd, NULL, NULL); closesocket(fd); fd = fd1; + ff_socket_nonblock(fd, 1); } else { redo: + ff_socket_nonblock(fd, 1); ret = connect(fd, cur_ai->ai_addr, cur_ai->ai_addrlen); } - ff_socket_nonblock(fd, 1); - if (ret < 0) { struct pollfd p = {fd, POLLOUT, 0}; - if (ff_neterrno() == AVERROR(EINTR)) { + ret = ff_neterrno(); + if (ret == AVERROR(EINTR)) { if (url_interrupt_cb()) { ret = AVERROR_EXIT; goto fail1; } goto redo; } - if (ff_neterrno() != AVERROR(EINPROGRESS) && - ff_neterrno() != AVERROR(EAGAIN)) + if (ret != AVERROR(EINPROGRESS) && + ret != AVERROR(EAGAIN)) goto fail; /* wait until we are connected or until abort */ - for(;;) { + while(timeout--) { if (url_interrupt_cb()) { ret = AVERROR_EXIT; goto fail1; @@ -114,7 +120,10 @@ static int tcp_open(URLContext *h, const char *uri, int flags) if (ret > 0) break; } - + if (ret <= 0) { + ret = AVERROR(ETIMEDOUT); + goto fail; + } /* test error */ optlen = sizeof(ret); getsockopt (fd, SOL_SOCKET, SO_ERROR, &ret, &optlen); @@ -122,6 +131,7 @@ static int tcp_open(URLContext *h, const char *uri, int flags) av_log(h, AV_LOG_ERROR, "TCP connection to %s:%d failed: %s\n", hostname, port, strerror(ret)); + ret = AVERROR(ret); goto fail; } } @@ -144,7 +154,6 @@ static int tcp_open(URLContext *h, const char *uri, int flags) closesocket(fd); goto restart; } - ret = AVERROR(EIO); fail1: if (fd >= 0) closesocket(fd); From 6348a96c06ca152f32fddac58552dd679d39eddf Mon Sep 17 00:00:00 2001 From: Luca Barbato Date: Thu, 26 May 2011 20:03:37 +0200 Subject: [PATCH 18/29] configure: report yasm/nasm presence properly If the secondary assembler is in use report the proper name --- configure | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure b/configure index d3e8764fb9..4916bad18a 100755 --- a/configure +++ b/configure @@ -3103,7 +3103,7 @@ fi echo "big-endian ${bigendian-no}" echo "runtime cpu detection ${runtime_cpudetect-no}" if enabled x86; then - echo "yasm ${yasm-no}" + echo "${yasmexe} ${yasm-no}" echo "MMX enabled ${mmx-no}" echo "MMX2 enabled ${mmx2-no}" echo "3DNow! enabled ${amd3dnow-no}" From 9f5d45025e8df9d5f39832caad16b94cb6ac11c5 Mon Sep 17 00:00:00 2001 From: "Ronald S. Bultje" Date: Fri, 27 May 2011 09:28:38 -0400 Subject: [PATCH 19/29] swscale: fix non-bitexact yuv2yuv[X2]() MMX/MMX2 functions. --- libswscale/x86/swscale_template.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/libswscale/x86/swscale_template.c b/libswscale/x86/swscale_template.c index fd59f763c5..a08ff6a0fb 100644 --- a/libswscale/x86/swscale_template.c +++ b/libswscale/x86/swscale_template.c @@ -59,7 +59,7 @@ "psraw $3, %%mm3 \n\t"\ "psraw $3, %%mm4 \n\t"\ "packuswb %%mm4, %%mm3 \n\t"\ - MOVNTQ(%%mm3, (%1, %%REGa))\ + MOVNTQ(%%mm3, (%1, %3))\ "add $8, %3 \n\t"\ "cmp %2, %3 \n\t"\ "movq "VROUNDER_OFFSET"(%0), %%mm3 \n\t"\ @@ -81,8 +81,9 @@ static inline void RENAME(yuv2yuvX)(SwsContext *c, const int16_t *lumFilter, uint8_t *aDest, long dstW, long chrDstW) { if (uDest) { + x86_reg uv_off = c->uv_off; YSCALEYUV2YV12X(CHR_MMX_FILTER_OFFSET, uDest, chrDstW, 0) - YSCALEYUV2YV12X(CHR_MMX_FILTER_OFFSET, vDest, chrDstW + c->uv_off, c->uv_off) + YSCALEYUV2YV12X(CHR_MMX_FILTER_OFFSET, vDest - uv_off, chrDstW + uv_off, uv_off) } if (CONFIG_SWSCALE_ALPHA && aDest) { YSCALEYUV2YV12X(ALP_MMX_FILTER_OFFSET, aDest, dstW, 0) @@ -137,7 +138,7 @@ static inline void RENAME(yuv2yuvX)(SwsContext *c, const int16_t *lumFilter, "psraw $3, %%mm4 \n\t"\ "psraw $3, %%mm6 \n\t"\ "packuswb %%mm6, %%mm4 \n\t"\ - MOVNTQ(%%mm4, (%1, %%REGa))\ + MOVNTQ(%%mm4, (%1, %3))\ "add $8, %3 \n\t"\ "cmp %2, %3 \n\t"\ "lea " offset "(%0), %%"REG_d" \n\t"\ @@ -161,8 +162,9 @@ static inline void RENAME(yuv2yuvX_ar)(SwsContext *c, const int16_t *lumFilter, uint8_t *aDest, long dstW, long chrDstW) { if (uDest) { + x86_reg uv_off = c->uv_off; YSCALEYUV2YV12X_ACCURATE(CHR_MMX_FILTER_OFFSET, uDest, chrDstW, 0) - YSCALEYUV2YV12X_ACCURATE(CHR_MMX_FILTER_OFFSET, vDest, chrDstW + c->uv_off, c->uv_off) + YSCALEYUV2YV12X_ACCURATE(CHR_MMX_FILTER_OFFSET, vDest - uv_off, chrDstW + uv_off, uv_off) } if (CONFIG_SWSCALE_ALPHA && aDest) { YSCALEYUV2YV12X_ACCURATE(ALP_MMX_FILTER_OFFSET, aDest, dstW, 0) From 91e3a25ef6de2efcbea38ec0f6ffd3f8785962a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Sat, 21 May 2011 14:57:04 +0300 Subject: [PATCH 20/29] movenc: Add an AVClass for setting muxer specific options MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Storsjö --- libavformat/movenc.c | 18 ++++++++++++++++++ libavformat/movenc.h | 1 + 2 files changed, 19 insertions(+) diff --git a/libavformat/movenc.c b/libavformat/movenc.c index 52c775a565..550b957b68 100644 --- a/libavformat/movenc.c +++ b/libavformat/movenc.c @@ -32,10 +32,22 @@ #include "libavcodec/put_bits.h" #include "internal.h" #include "libavutil/avstring.h" +#include "libavutil/opt.h" #undef NDEBUG #include +static const AVOption options[] = { + { NULL }, +}; + +static const AVClass mov_muxer_class = { + .class_name = "MOV/3GP/MP4/3G2 muxer", + .item_name = av_default_item_name, + .option = options, + .version = LIBAVUTIL_VERSION_INT, +}; + //FIXME support 64 bit variant with wide placeholders static int64_t updateSize(AVIOContext *pb, int64_t pos) { @@ -2285,6 +2297,7 @@ AVOutputFormat ff_mov_muxer = { mov_write_trailer, .flags = AVFMT_GLOBALHEADER, .codec_tag = (const AVCodecTag* const []){codec_movvideo_tags, codec_movaudio_tags, 0}, + .priv_class = &mov_muxer_class, }; #endif #if CONFIG_TGP_MUXER @@ -2301,6 +2314,7 @@ AVOutputFormat ff_tgp_muxer = { mov_write_trailer, .flags = AVFMT_GLOBALHEADER, .codec_tag = (const AVCodecTag* const []){codec_3gp_tags, 0}, + .priv_class = &mov_muxer_class, }; #endif #if CONFIG_MP4_MUXER @@ -2317,6 +2331,7 @@ AVOutputFormat ff_mp4_muxer = { mov_write_trailer, .flags = AVFMT_GLOBALHEADER, .codec_tag = (const AVCodecTag* const []){ff_mp4_obj_type, 0}, + .priv_class = &mov_muxer_class, }; #endif #if CONFIG_PSP_MUXER @@ -2333,6 +2348,7 @@ AVOutputFormat ff_psp_muxer = { mov_write_trailer, .flags = AVFMT_GLOBALHEADER, .codec_tag = (const AVCodecTag* const []){ff_mp4_obj_type, 0}, + .priv_class = &mov_muxer_class, }; #endif #if CONFIG_TG2_MUXER @@ -2349,6 +2365,7 @@ AVOutputFormat ff_tg2_muxer = { mov_write_trailer, .flags = AVFMT_GLOBALHEADER, .codec_tag = (const AVCodecTag* const []){codec_3gp_tags, 0}, + .priv_class = &mov_muxer_class, }; #endif #if CONFIG_IPOD_MUXER @@ -2365,5 +2382,6 @@ AVOutputFormat ff_ipod_muxer = { mov_write_trailer, .flags = AVFMT_GLOBALHEADER, .codec_tag = (const AVCodecTag* const []){codec_ipod_tags, 0}, + .priv_class = &mov_muxer_class, }; #endif diff --git a/libavformat/movenc.h b/libavformat/movenc.h index 0cc1eb8dc9..6e2b5b7a99 100644 --- a/libavformat/movenc.h +++ b/libavformat/movenc.h @@ -101,6 +101,7 @@ typedef struct MOVIndex { } MOVTrack; typedef struct MOVMuxContext { + const AVClass *av_class; int mode; int64_t time; int nb_streams; From 28734ac995ef4ea9be2203144362a585b2296637 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Fri, 20 May 2011 12:27:02 +0300 Subject: [PATCH 21/29] movenc: Deprecate the global RTP hinting flag, use a private AVOption instead MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Instead of -fflags rtphint, set -movflags rtphint instead. Signed-off-by: Martin Storsjö --- libavformat/avformat.h | 4 +++- libavformat/movenc.c | 12 +++++++++++- libavformat/movenc.h | 4 ++++ libavformat/options.c | 4 +++- libavformat/version.h | 3 +++ 5 files changed, 24 insertions(+), 3 deletions(-) diff --git a/libavformat/avformat.h b/libavformat/avformat.h index 2ea940c186..849a85d1cc 100644 --- a/libavformat/avformat.h +++ b/libavformat/avformat.h @@ -723,7 +723,9 @@ typedef struct AVFormatContext { #define AVFMT_FLAG_IGNDTS 0x0008 ///< Ignore DTS on frames that contain both DTS & PTS #define AVFMT_FLAG_NOFILLIN 0x0010 ///< Do not infer any values from other values, just return what is stored in the container #define AVFMT_FLAG_NOPARSE 0x0020 ///< Do not use AVParsers, you also must set AVFMT_FLAG_NOFILLIN as the fillin code works on frames and no parsing -> no frames. Also seeking to frames can not work if parsing to find frame boundaries has been disabled -#define AVFMT_FLAG_RTP_HINT 0x0040 ///< Add RTP hinting to the output file +#if FF_API_FLAG_RTP_HINT +#define AVFMT_FLAG_RTP_HINT 0x0040 ///< Deprecated, use the -movflags rtphint muxer specific AVOption instead +#endif int loop_input; diff --git a/libavformat/movenc.c b/libavformat/movenc.c index 550b957b68..2b6539d140 100644 --- a/libavformat/movenc.c +++ b/libavformat/movenc.c @@ -38,6 +38,8 @@ #include static const AVOption options[] = { + { "movflags", "MOV muxer flags", offsetof(MOVMuxContext, flags), FF_OPT_TYPE_FLAGS, {.dbl = 0}, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, "movflags" }, + { "rtphint", "Add RTP hint tracks", 0, FF_OPT_TYPE_CONST, {.dbl = FF_MOV_FLAG_RTP_HINT}, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, "movflags" }, { NULL }, }; @@ -2124,7 +2126,15 @@ static int mov_write_header(AVFormatContext *s) if (mov->mode & (MODE_MOV|MODE_IPOD) && s->nb_chapters) mov->chapter_track = mov->nb_streams++; +#if FF_API_FLAG_RTP_HINT if (s->flags & AVFMT_FLAG_RTP_HINT) { + av_log(s, AV_LOG_WARNING, "The RTP_HINT flag is deprecated, enable it " + "via the -movflags rtphint muxer option " + "instead.\n"); + mov->flags |= FF_MOV_FLAG_RTP_HINT; + } +#endif + if (mov->flags & FF_MOV_FLAG_RTP_HINT) { /* Add hint tracks for each audio and video stream */ hint_track = mov->nb_streams; for (i = 0; i < s->nb_streams; i++) { @@ -2220,7 +2230,7 @@ static int mov_write_header(AVFormatContext *s) if (mov->chapter_track) mov_create_chapter_track(s, mov->chapter_track); - if (s->flags & AVFMT_FLAG_RTP_HINT) { + if (mov->flags & FF_MOV_FLAG_RTP_HINT) { /* Initialize the hint tracks for each audio and video stream */ for (i = 0; i < s->nb_streams; i++) { AVStream *st = s->streams[i]; diff --git a/libavformat/movenc.h b/libavformat/movenc.h index 6e2b5b7a99..69b6621711 100644 --- a/libavformat/movenc.h +++ b/libavformat/movenc.h @@ -109,8 +109,12 @@ typedef struct MOVMuxContext { int64_t mdat_pos; uint64_t mdat_size; MOVTrack *tracks; + + int flags; } MOVMuxContext; +#define FF_MOV_FLAG_RTP_HINT 1 + int ff_mov_write_packet(AVFormatContext *s, AVPacket *pkt); int ff_mov_init_hinting(AVFormatContext *s, int index, int src_index); diff --git a/libavformat/options.c b/libavformat/options.c index 377ba93b44..6ffd1a7435 100644 --- a/libavformat/options.c +++ b/libavformat/options.c @@ -49,7 +49,9 @@ static const AVOption options[]={ {"nofillin", "do not fill in missing values that can be exactly calculated", 0, FF_OPT_TYPE_CONST, {.dbl = AVFMT_FLAG_NOFILLIN }, INT_MIN, INT_MAX, D, "fflags"}, {"noparse", "disable AVParsers, this needs nofillin too", 0, FF_OPT_TYPE_CONST, {.dbl = AVFMT_FLAG_NOPARSE }, INT_MIN, INT_MAX, D, "fflags"}, {"igndts", "ignore dts", 0, FF_OPT_TYPE_CONST, {.dbl = AVFMT_FLAG_IGNDTS }, INT_MIN, INT_MAX, D, "fflags"}, -{"rtphint", "add rtp hinting", 0, FF_OPT_TYPE_CONST, {.dbl = AVFMT_FLAG_RTP_HINT }, INT_MIN, INT_MAX, E, "fflags"}, +#if FF_API_FLAG_RTP_HINT +{"rtphint", "add rtp hinting (deprecated, use the -movflags rtphint option instead)", 0, FF_OPT_TYPE_CONST, {.dbl = AVFMT_FLAG_RTP_HINT }, INT_MIN, INT_MAX, E, "fflags"}, +#endif {"analyzeduration", "how many microseconds are analyzed to estimate duration", OFFSET(max_analyze_duration), FF_OPT_TYPE_INT, {.dbl = 5*AV_TIME_BASE }, 0, INT_MAX, D}, {"cryptokey", "decryption key", OFFSET(key), FF_OPT_TYPE_BINARY, {.dbl = 0}, 0, 0, D}, {"indexmem", "max memory used for timestamp index (per stream)", OFFSET(max_index_size), FF_OPT_TYPE_INT, {.dbl = 1<<20 }, 0, INT_MAX, D}, diff --git a/libavformat/version.h b/libavformat/version.h index b2ac6d8181..0b53005a6f 100644 --- a/libavformat/version.h +++ b/libavformat/version.h @@ -71,5 +71,8 @@ #ifndef FF_API_FORMAT_PARAMETERS #define FF_API_FORMAT_PARAMETERS (LIBAVFORMAT_VERSION_MAJOR < 54) #endif +#ifndef FF_API_FLAG_RTP_HINT +#define FF_API_FLAG_RTP_HINT (LIBAVFORMAT_VERSION_MAJOR < 54) +#endif #endif /* AVFORMAT_VERSION_H */ From f327bfa6dcdbce4593213c30a328d8aaf7a4b86b Mon Sep 17 00:00:00 2001 From: "Ronald S. Bultje" Date: Fri, 27 May 2011 11:36:43 -0400 Subject: [PATCH 22/29] swscale: fix build with --disable-swscale-alpha. --- libswscale/x86/yuv2rgb_mmx.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libswscale/x86/yuv2rgb_mmx.c b/libswscale/x86/yuv2rgb_mmx.c index 23d4c42700..439482bb71 100644 --- a/libswscale/x86/yuv2rgb_mmx.c +++ b/libswscale/x86/yuv2rgb_mmx.c @@ -82,15 +82,15 @@ SwsFunc ff_yuv2rgb_init_mmx(SwsContext *c) if (HAVE_MMX && cpu_flags & AV_CPU_FLAG_MMX) { switch (c->dstFormat) { case PIX_FMT_RGB32: - if (CONFIG_SWSCALE_ALPHA && c->srcFormat == PIX_FMT_YUVA420P) { -#if HAVE_7REGS + if (c->srcFormat == PIX_FMT_YUVA420P) { +#if HAVE_7REGS && CONFIG_SWSCALE_ALPHA return yuva420_rgb32_MMX; #endif break; } else return yuv420_rgb32_MMX; case PIX_FMT_BGR32: - if (CONFIG_SWSCALE_ALPHA && c->srcFormat == PIX_FMT_YUVA420P) { -#if HAVE_7REGS + if (c->srcFormat == PIX_FMT_YUVA420P) { +#if HAVE_7REGS && CONFIG_SWSCALE_ALPHA return yuva420_bgr32_MMX; #endif break; From 389e2000ebc299b9da24f7e5faf9a68a88f9ee7c Mon Sep 17 00:00:00 2001 From: "Ronald S. Bultje" Date: Fri, 27 May 2011 12:23:32 -0400 Subject: [PATCH 23/29] swscale: delay allocation of formatConvBuffer(). That means it won't be allocated when not needed. Alongside this, it fixes valgrind/fate-detected memory leaks. --- libswscale/utils.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libswscale/utils.c b/libswscale/utils.c index 15ed9d1ce6..571f45be3d 100644 --- a/libswscale/utils.c +++ b/libswscale/utils.c @@ -791,7 +791,6 @@ int sws_init_context(SwsContext *c, SwsFilter *srcFilter, SwsFilter *dstFilter) srcW, srcH, dstW, dstH); return AVERROR(EINVAL); } - FF_ALLOC_OR_GOTO(c, c->formatConvBuffer, FFALIGN(srcW, 16) * 2, fail); if (!dstFilter) dstFilter= &dummyFilter; if (!srcFilter) srcFilter= &dummyFilter; @@ -847,6 +846,7 @@ int sws_init_context(SwsContext *c, SwsFilter *srcFilter, SwsFilter *dstFilter) } } + FF_ALLOC_OR_GOTO(c, c->formatConvBuffer, FFALIGN(srcW, 16) * 2, fail); if (HAVE_MMX2 && cpu_flags & AV_CPU_FLAG_MMX2) { c->canMMX2BeUsed= (dstW >=srcW && (dstW&31)==0 && (srcW&15)==0) ? 1 : 0; if (!c->canMMX2BeUsed && dstW >=srcW && (srcW&15)==0 && (flags&SWS_FAST_BILINEAR)) { From faf8d3ddfa105d7f107a886c5f3cadf6357d89b6 Mon Sep 17 00:00:00 2001 From: "Ronald S. Bultje" Date: Fri, 27 May 2011 11:57:39 -0400 Subject: [PATCH 24/29] cmdutils: use sws_freeContext() instead of av_freep(). av_freep(swsContext) will leak all memory potentially allocated within the swsContext. --- cmdutils.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cmdutils.c b/cmdutils.c index feeea694d8..778f0fb3cf 100644 --- a/cmdutils.c +++ b/cmdutils.c @@ -76,7 +76,8 @@ void uninit_opts(void) av_freep(&avformat_opts->key); av_freep(&avformat_opts); #if CONFIG_SWSCALE - av_freep(&sws_opts); + sws_freeContext(sws_opts); + sws_opts = NULL; #endif for (i = 0; i < opt_name_count; i++) { //opt_values are only stored for codec-specific options in which case From 5e528cffcf3d2cb1665075649601f4e62c8764e1 Mon Sep 17 00:00:00 2001 From: Diego Biurrun Date: Fri, 27 May 2011 21:18:12 +0200 Subject: [PATCH 25/29] x86: Add appropriate ifdefs around certain AVX functions. nasm versions prior to 2.09 have trouble assembling some of our AVX code. Protect these sections by preprocessor macros to allow compilation to pass. --- libavcodec/x86/fft_mmx.asm | 8 ++++++++ libavcodec/x86/fft_sse.c | 3 +++ 2 files changed, 11 insertions(+) diff --git a/libavcodec/x86/fft_mmx.asm b/libavcodec/x86/fft_mmx.asm index bd2e8297e7..27276a1a31 100644 --- a/libavcodec/x86/fft_mmx.asm +++ b/libavcodec/x86/fft_mmx.asm @@ -299,6 +299,7 @@ IF%1 mova Z(1), m5 INIT_YMM +%ifdef HAVE_AVX align 16 fft8_avx: mova m0, Z(0) @@ -387,6 +388,7 @@ fft32_interleave_avx: sub r2d, mmsize/4 jg .deint_loop ret +%endif INIT_XMM %define movdqa movaps @@ -532,6 +534,7 @@ DEFINE_ARGS z, w, n, o1, o3 INIT_YMM +%ifdef HAVE_AVX %macro INTERL_AVX 5 vunpckhps %3, %2, %1 vunpcklps %2, %2, %1 @@ -545,6 +548,7 @@ INIT_YMM DECL_PASS pass_avx, PASS_BIG 1 DECL_PASS pass_interleave_avx, PASS_BIG 0 +%endif INIT_XMM @@ -634,8 +638,10 @@ cglobal fft_dispatch%3%2, 2,5,8, z, nbits RET %endmacro ; DECL_FFT +%ifdef HAVE_AVX DECL_FFT 6, _avx DECL_FFT 6, _avx, _interleave +%endif DECL_FFT 5, _sse DECL_FFT 5, _sse, _interleave DECL_FFT 4, _3dn @@ -847,4 +853,6 @@ DECL_IMDCT _sse, POSROTATESHUF INIT_YMM +%ifdef HAVE_AVX DECL_IMDCT _avx, POSROTATESHUF_AVX +%endif diff --git a/libavcodec/x86/fft_sse.c b/libavcodec/x86/fft_sse.c index 5b52988d09..add20dd5b2 100644 --- a/libavcodec/x86/fft_sse.c +++ b/libavcodec/x86/fft_sse.c @@ -22,6 +22,7 @@ #include "libavutil/x86_cpu.h" #include "libavcodec/dsputil.h" #include "fft.h" +#include "config.h" DECLARE_ASM_CONST(16, int, ff_m1m1m1m1)[4] = { 1 << 31, 1 << 31, 1 << 31, 1 << 31 }; @@ -30,10 +31,12 @@ void ff_fft_dispatch_sse(FFTComplex *z, int nbits); void ff_fft_dispatch_interleave_sse(FFTComplex *z, int nbits); void ff_fft_dispatch_interleave_avx(FFTComplex *z, int nbits); +#if HAVE_AVX void ff_fft_calc_avx(FFTContext *s, FFTComplex *z) { ff_fft_dispatch_interleave_avx(z, s->nbits); } +#endif void ff_fft_calc_sse(FFTContext *s, FFTComplex *z) { From 7eae0110022063d0b3eb423c46dea5eff5268797 Mon Sep 17 00:00:00 2001 From: Diego Biurrun Date: Thu, 26 May 2011 14:39:37 +0200 Subject: [PATCH 26/29] doc: Drop DJGPP section, Libav now compiles out-of-the-box on FreeDOS. --- doc/general.texi | 6 ------ 1 file changed, 6 deletions(-) diff --git a/doc/general.texi b/doc/general.texi index 94fdb1dec4..23a789572d 100644 --- a/doc/general.texi +++ b/doc/general.texi @@ -754,12 +754,6 @@ performance on systems without hardware floating point support). Using a cross-compiler is preferred for various reasons. -@subsection DJGPP - -Libav cannot be compiled because of broken system headers, add -@code{--extra-cflags=-U__STRICT_ANSI__} to the configure options as a -workaround. - @section OS/2 For information about compiling Libav on OS/2 see From 5a5a0f161359ca6c3fd03eac88a57bd026b8bc1d Mon Sep 17 00:00:00 2001 From: Diego Biurrun Date: Fri, 27 May 2011 19:46:39 +0200 Subject: [PATCH 27/29] swscale: Remove unused variables in x86 code. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit libswscale/x86/swscale_template.c:2072: warning: unused variable ‘canMMX2BeUsed’ libswscale/x86/swscale_template.c:2145: warning: unused variable ‘canMMX2BeUsed’ libswscale/x86/swscale_template.c:2209: warning: unused variable ‘chrVPixBuf’ libswscale/x86/swscale_template.c:2237: warning: unused variable ‘chrVSrcPtr’ --- libswscale/x86/swscale_template.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/libswscale/x86/swscale_template.c b/libswscale/x86/swscale_template.c index a08ff6a0fb..5cc3a435be 100644 --- a/libswscale/x86/swscale_template.c +++ b/libswscale/x86/swscale_template.c @@ -2071,7 +2071,6 @@ static inline void RENAME(hyscale_fast)(SwsContext *c, int16_t *dst, { int32_t *filterPos = c->hLumFilterPos; int16_t *filter = c->hLumFilter; - int canMMX2BeUsed = c->canMMX2BeUsed; void *mmx2FilterCode= c->lumMmx2FilterCode; int i; #if defined(PIC) @@ -2144,7 +2143,6 @@ static inline void RENAME(hcscale_fast)(SwsContext *c, int16_t *dst1, int16_t *d { int32_t *filterPos = c->hChrFilterPos; int16_t *filter = c->hChrFilter; - int canMMX2BeUsed = c->canMMX2BeUsed; void *mmx2FilterCode= c->chrMmx2FilterCode; int i; #if defined(PIC) @@ -2210,7 +2208,6 @@ static void updateMMXDitherTables(SwsContext *c, int dstY, int lumBufIndex, int const int flags= c->flags; int16_t **lumPixBuf= c->lumPixBuf; int16_t **chrUPixBuf= c->chrUPixBuf; - int16_t **chrVPixBuf= c->chrVPixBuf; int16_t **alpPixBuf= c->alpPixBuf; const int vLumBufSize= c->vLumBufSize; const int vChrBufSize= c->vChrBufSize; @@ -2236,7 +2233,6 @@ static void updateMMXDitherTables(SwsContext *c, int dstY, int lumBufIndex, int if (dstY < dstH - 2) { const int16_t **lumSrcPtr= (const int16_t **) lumPixBuf + lumBufIndex + firstLumSrcY - lastInLumBuf + vLumBufSize; const int16_t **chrUSrcPtr= (const int16_t **) chrUPixBuf + chrBufIndex + firstChrSrcY - lastInChrBuf + vChrBufSize; - const int16_t **chrVSrcPtr= (const int16_t **) chrVPixBuf + chrBufIndex + firstChrSrcY - lastInChrBuf + vChrBufSize; const int16_t **alpSrcPtr= (CONFIG_SWSCALE_ALPHA && alpPixBuf) ? (const int16_t **) alpPixBuf + lumBufIndex + firstLumSrcY - lastInLumBuf + vLumBufSize : NULL; int i; if (flags & SWS_ACCURATE_RND) { From 93eb8e4d7c6654040fd160396546c547cdf51043 Mon Sep 17 00:00:00 2001 From: Mans Rullgard Date: Fri, 27 May 2011 20:12:01 +0100 Subject: [PATCH 28/29] ARM: check for VFPv3 Signed-off-by: Mans Rullgard --- configure | 3 +++ 1 file changed, 3 insertions(+) diff --git a/configure b/configure index 4916bad18a..46593882df 100755 --- a/configure +++ b/configure @@ -1020,6 +1020,7 @@ ARCH_EXT_LIST=' ppc4xx sse ssse3 + vfpv3 vis ' @@ -1205,6 +1206,7 @@ armv6t2_deps="arm" armvfp_deps="arm" iwmmxt_deps="arm" neon_deps="arm" +vfpv3_deps="armvfp" mmi_deps="mips" @@ -2628,6 +2630,7 @@ EOF enabled armvfp && check_asm armvfp '"fadds s0, s0, s0"' enabled iwmmxt && check_asm iwmmxt '"wunpckelub wr6, wr4"' enabled neon && check_asm neon '"vadd.i16 q0, q0, q0"' + enabled vfpv3 && check_asm vfpv3 '"vmov.f32 s0, #1.0"' enabled_all armv6t2 shared !pic && enable_pic From 79aeade6f6f8fbd7ce1da619fdd475e5db88ae24 Mon Sep 17 00:00:00 2001 From: Mans Rullgard Date: Fri, 27 May 2011 20:18:26 +0100 Subject: [PATCH 29/29] ARM: disable ff_vector_fmul_vfp on VFPv3 systems This function uses old-style vector operations deprecated in VFPv3. Some implementations, e.g. Cortex-A9, support them only through slow software emulation. Cortex-A8 does have this functionality in hardware, but as it also has NEON, this function is not used there regardless. Signed-off-by: Mans Rullgard --- libavcodec/arm/dsputil_init_vfp.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libavcodec/arm/dsputil_init_vfp.c b/libavcodec/arm/dsputil_init_vfp.c index 39289116ef..9cda890411 100644 --- a/libavcodec/arm/dsputil_init_vfp.c +++ b/libavcodec/arm/dsputil_init_vfp.c @@ -28,6 +28,7 @@ void ff_vector_fmul_reverse_vfp(float *dst, const float *src0, void ff_dsputil_init_vfp(DSPContext* c, AVCodecContext *avctx) { - c->vector_fmul = ff_vector_fmul_vfp; + if (!HAVE_VFPV3) + c->vector_fmul = ff_vector_fmul_vfp; c->vector_fmul_reverse = ff_vector_fmul_reverse_vfp; }