[libav-commits] avconv: fix off by one check in complex_filter

2012-04-22 Thread Luca Barbato
Module: libav
Branch: master
Commit: 1381081cdb5999892d69f2ff010cf9371bfc7978

Author:Luca Barbato 
Committer: Luca Barbato 
Date:  Sun Apr 22 16:37:54 2012 -0700

avconv: fix off by one check in complex_filter

nb_input_files is already an invalid index.

---

 avconv.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/avconv.c b/avconv.c
index 851d8dd..e441fff 100644
--- a/avconv.c
+++ b/avconv.c
@@ -725,7 +725,7 @@ static void init_input_filter(FilterGraph *fg, 
AVFilterInOut *in)
 char *p;
 int file_idx = strtol(in->name, &p, 0);
 
-if (file_idx < 0 || file_idx > nb_input_files) {
+if (file_idx < 0 || file_idx >= nb_input_files) {
 av_log(NULL, AV_LOG_FATAL, "Invalid file index %d in filtegraph 
description %s.\n",
file_idx, fg->graph_desc);
 exit_program(1);

___
libav-commits mailing list
libav-commits@libav.org
https://lists.libav.org/mailman/listinfo/libav-commits


[libav-commits] matroska: Add incremental parsing of clusters.

2012-04-22 Thread Dale Curtis
Module: libav
Branch: master
Commit: 8336eb6f85e4b94b9c198b16bd0ac4178f4dba86

Author:Dale Curtis 
Committer: Luca Barbato 
Date:  Thu Apr 19 11:12:24 2012 -0700

matroska: Add incremental parsing of clusters.

Reduces the amount of upfront data required for cluster parsing
thus decreasing latency on seek and startup.

The change in the seek-lavf_mkv FATE test is due to incremental
parsing no longer reading as much data as the old parser and
thus not having that additional data to generate index entries
based on keyframes.  Index entries are added correctly as the
file is parsed.

All FATE tests pass and Chrome has been using this patch for ~6
months without issue.

Currently incremental parsing is not supported for files with
SSA tracks since they require merging packets between clusters.
In this case the code falls back to non-incremental parsing.

Signed-off-by: Aaron Colwell 
Signed-off-by: Dale Curtis 
Signed-off-by: Luca Barbato 

---

 libavformat/matroskadec.c |  113 ++--
 tests/ref/seek/lavf_mkv   |2 +-
 2 files changed, 108 insertions(+), 7 deletions(-)

diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
index 99e0dac..100b97f 100644
--- a/libavformat/matroskadec.c
+++ b/libavformat/matroskadec.c
@@ -213,6 +213,11 @@ typedef struct {
 } MatroskaLevel;
 
 typedef struct {
+uint64_t timecode;
+EbmlList blocks;
+} MatroskaCluster;
+
+typedef struct {
 AVFormatContext *ctx;
 
 /* EBML stuff */
@@ -247,6 +252,13 @@ typedef struct {
 
 /* File has a CUES element, but we defer parsing until it is needed. */
 int cues_parsing_deferred;
+
+int current_cluster_num_blocks;
+int64_t current_cluster_pos;
+MatroskaCluster current_cluster;
+
+/* File has SSA subtitles which prevent incremental cluster parsing. */
+int contains_ssa;
 } MatroskaDemuxContext;
 
 typedef struct {
@@ -256,11 +268,6 @@ typedef struct {
 EbmlBin  bin;
 } MatroskaBlock;
 
-typedef struct {
-uint64_t timecode;
-EbmlList blocks;
-} MatroskaCluster;
-
 static EbmlSyntax ebml_header[] = {
 { EBML_ID_EBMLREADVERSION,EBML_UINT, 0, offsetof(Ebml,version), 
{.u=EBML_VERSION} },
 { EBML_ID_EBMLMAXSIZELENGTH,  EBML_UINT, 0, offsetof(Ebml,max_size), 
{.u=8} },
@@ -514,6 +521,38 @@ static EbmlSyntax matroska_clusters[] = {
 { 0 }
 };
 
+static EbmlSyntax matroska_cluster_incremental_parsing[] = {
+{ MATROSKA_ID_CLUSTERTIMECODE,EBML_UINT,0, 
offsetof(MatroskaCluster,timecode) },
+{ MATROSKA_ID_BLOCKGROUP, EBML_NEST, sizeof(MatroskaBlock), 
offsetof(MatroskaCluster,blocks), {.n=matroska_blockgroup} },
+{ MATROSKA_ID_SIMPLEBLOCK,EBML_PASS, sizeof(MatroskaBlock), 
offsetof(MatroskaCluster,blocks), {.n=matroska_blockgroup} },
+{ MATROSKA_ID_CLUSTERPOSITION,EBML_NONE },
+{ MATROSKA_ID_CLUSTERPREVSIZE,EBML_NONE },
+{ MATROSKA_ID_INFO,   EBML_NONE },
+{ MATROSKA_ID_CUES,   EBML_NONE },
+{ MATROSKA_ID_TAGS,   EBML_NONE },
+{ MATROSKA_ID_SEEKHEAD,   EBML_NONE },
+{ MATROSKA_ID_CLUSTER,EBML_STOP },
+{ 0 }
+};
+
+static EbmlSyntax matroska_cluster_incremental[] = {
+{ MATROSKA_ID_CLUSTERTIMECODE,EBML_UINT,0, 
offsetof(MatroskaCluster,timecode) },
+{ MATROSKA_ID_BLOCKGROUP, EBML_STOP },
+{ MATROSKA_ID_SIMPLEBLOCK,EBML_STOP },
+{ MATROSKA_ID_CLUSTERPOSITION,EBML_NONE },
+{ MATROSKA_ID_CLUSTERPREVSIZE,EBML_NONE },
+{ 0 }
+};
+
+static EbmlSyntax matroska_clusters_incremental[] = {
+{ MATROSKA_ID_CLUSTER,EBML_NEST, 0, 0, 
{.n=matroska_cluster_incremental} },
+{ MATROSKA_ID_INFO,   EBML_NONE },
+{ MATROSKA_ID_CUES,   EBML_NONE },
+{ MATROSKA_ID_TAGS,   EBML_NONE },
+{ MATROSKA_ID_SEEKHEAD,   EBML_NONE },
+{ 0 }
+};
+
 static const char *const matroska_doctypes[] = { "matroska", "webm" };
 
 /*
@@ -1563,6 +1602,8 @@ static int matroska_read_header(AVFormatContext *s)
 st->need_parsing = AVSTREAM_PARSE_HEADERS;
 } else if (track->type == MATROSKA_TRACK_TYPE_SUBTITLE) {
 st->codec->codec_type = AVMEDIA_TYPE_SUBTITLE;
+if (st->codec->codec_id == CODEC_ID_SSA)
+matroska->contains_ssa = 1;
 }
 }
 
@@ -1634,6 +1675,7 @@ static int matroska_deliver_packet(MatroskaDemuxContext 
*matroska,
 matroska->packets = newpackets;
 } else {
 av_freep(&matroska->packets);
+matroska->prev_pkt = NULL;
 }
 matroska->num_packets--;
 return 0;
@@ -1929,13 +1971,71 @@ end:
 return res;
 }
 
+static int matroska_parse_cluster_incremental(MatroskaDemuxContext *matroska)
+{
+EbmlList *blocks_list;
+MatroskaBlock *blocks;
+int i, res;
+res = ebml_parse(matroska,
+ matroska_cluster_incremental_parsing,
+ &matroska->current_cluster);
+if (res == 1) {
+/* New Clu

[libav-commits] mpegts: Try seeking back even for nonseekable protocols

2012-04-22 Thread Martin Storsjö
Module: libav
Branch: master
Commit: 269cb6751b3fd2163253f9a8ea0d193121858677

Author:Martin Storsjö 
Committer: Martin Storsjö 
Date:  Sat Apr 21 22:48:34 2012 +0300

mpegts: Try seeking back even for nonseekable protocols

The mpegts demuxer reads 5 KB at startup just for discovering
the packet size. Since the default avio buffer size is 32 KB,
the seek back to the start will in most cases be within the
avio buffer, and will in most cases succeed even if the actual
protocol isn't seekable.

This makes the demuxer startup faster/with less data when
reading data from a non-seekable input, by not skipping
the first few KB.

If it fails, don't warn if the protocol isn't seekable, making
it behave as before in the failure case.

Signed-off-by: Martin Storsjö 

---

 libavformat/mpegts.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c
index e067927..c853e72 100644
--- a/libavformat/mpegts.c
+++ b/libavformat/mpegts.c
@@ -1899,7 +1899,7 @@ static int mpegts_read_header(AVFormatContext *s)
 /* normal demux */
 
 /* first do a scan to get all the services */
-if (pb->seekable && avio_seek(pb, pos, SEEK_SET) < 0)
+if (avio_seek(pb, pos, SEEK_SET) < 0 && pb->seekable)
 av_log(s, AV_LOG_ERROR, "Unable to seek back to the start\n");
 
 mpegts_open_section_filter(ts, SDT_PID, sdt_cb, ts, 1);

___
libav-commits mailing list
libav-commits@libav.org
https://lists.libav.org/mailman/listinfo/libav-commits

[libav-commits] swscale: K&R formatting cosmetics (part III)

2012-04-22 Thread Diego Biurrun
Module: libav
Branch: master
Commit: 9b75ae05cf1554238bb103b3c3304dcba0bbc6cf

Author:Diego Biurrun 
Committer: Diego Biurrun 
Date:  Sun Apr 15 21:33:30 2012 +0200

swscale: K&R formatting cosmetics (part III)

---

 libswscale/input.c |  933 
 1 files changed, 575 insertions(+), 358 deletions(-)

diff --git a/libswscale/input.c b/libswscale/input.c
index b485509..afc5156 100644
--- a/libswscale/input.c
+++ b/libswscale/input.c
@@ -36,66 +36,73 @@
 #include "swscale_internal.h"
 
 #define RGB2YUV_SHIFT 15
-#define BY ( (int)(0.114*219/255*(1<> 
RGB2YUV_SHIFT;
+dst[i] = (RY * r + GY * g + BY * b + (0x2001 << (RGB2YUV_SHIFT - 1))) 
>> RGB2YUV_SHIFT;
 }
 }
 
-static av_always_inline void
-rgb48ToUV_c_template(uint16_t *dstU, uint16_t *dstV,
-const uint16_t *src1, const uint16_t *src2,
-int width, enum PixelFormat origin)
+static av_always_inline void rgb48ToUV_c_template(uint16_t *dstU,
+  uint16_t *dstV,
+  const uint16_t *src1,
+  const uint16_t *src2,
+  int width,
+  enum PixelFormat origin)
 {
 int i;
-assert(src1==src2);
+assert(src1 == src2);
 for (i = 0; i < width; i++) {
-int r_b = input_pixel(&src1[i*3+0]);
-int   g = input_pixel(&src1[i*3+1]);
-int b_r = input_pixel(&src1[i*3+2]);
+int r_b = input_pixel(&src1[i * 3 + 0]);
+int g   = input_pixel(&src1[i * 3 + 1]);
+int b_r = input_pixel(&src1[i * 3 + 2]);
 
-dstU[i] = (RU*r + GU*g + BU*b + (0x10001<<(RGB2YUV_SHIFT-1))) >> 
RGB2YUV_SHIFT;
-dstV[i] = (RV*r + GV*g + BV*b + (0x10001<<(RGB2YUV_SHIFT-1))) >> 
RGB2YUV_SHIFT;
+dstU[i] = (RU * r + GU * g + BU * b + (0x10001 << (RGB2YUV_SHIFT - 
1))) >> RGB2YUV_SHIFT;
+dstV[i] = (RV * r + GV * g + BV * b + (0x10001 << (RGB2YUV_SHIFT - 
1))) >> RGB2YUV_SHIFT;
 }
 }
 
-static av_always_inline void
-rgb48ToUV_half_c_template(uint16_t *dstU, uint16_t *dstV,
-  const uint16_t *src1, const uint16_t *src2,
-  int width, enum PixelFormat origin)
+static av_always_inline void rgb48ToUV_half_c_template(uint16_t *dstU,
+   uint16_t *dstV,
+   const uint16_t *src1,
+   const uint16_t *src2,
+   int width,
+   enum PixelFormat origin)
 {
 int i;
-assert(src1==src2);
+assert(src1 == src2);
 for (i = 0; i < width; i++) {
-int r_b = (input_pixel(&src1[6 * i + 0]) + input_pixel(&src1[6 * i + 
3]) + 1) >> 1;
-int   g = (input_pixel(&src1[6 * i + 1]) + input_pixel(&src1[6 * i + 
4]) + 1) >> 1;
-int b_r = (input_pixel(&src1[6 * i + 2]) + input_pixel(&src1[6 * i + 
5]) + 1) >> 1;
+int r_b = (input_pixel(&src1[6 * i + 0]) +
+   input_pixel(&src1[6 * i + 3]) + 1) >> 1;
+int g   = (input_pixel(&src1[6 * i + 1]) +
+   input_pixel(&src1[6 * i + 4]) + 1) >> 1;
+int b_r = (input_pixel(&src1[6 * i + 2]) +
+   input_pixel(&src1[6 * i + 5]) + 1) >> 1;
 
-dstU[i]= (RU*r + GU*g + BU*b + (0x10001<<(RGB2YUV_SHIFT-1))) >> 
RGB2YUV_SHIFT;
-dstV[i]= (RV*r + GV*g + BV*b + (0x10001<<(RGB2YUV_SHIFT-1))) >> 
RGB2YUV_SHIFT;
+dstU[i] = (RU * r + GU * g + BU * b + (0x10001 << (RGB2YUV_SHIFT - 
1))) >> RGB2YUV_SHIFT;
+dstV[i] = (RV * r + GV * g + BV * b + (0x10001 << (RGB2YUV_SHIFT - 
1))) >> RGB2YUV_SHIFT;
 }
 }
 
@@ -103,33 +110,43 @@ rgb48ToUV_half_c_template(uint16_t *dstU, uint16_t *dstV,
 #undef b
 #undef input_pixel
 
-#define rgb48funcs(pattern, BE_LE, origin) \
-static void pattern ## 48 ## BE_LE ## ToY_c(uint8_t *_dst, const uint8_t 
*_src, \
-int width, uint32_t *unused) \
-{ \
-const uint16_t *src = (const uint16_t *) _src; \
-uint16_t *dst = (uint16_t *) _dst; \
-rgb48ToY_c_template(dst, src, width, origin); \
-} \
- \
-static void pattern ## 48 ## BE_LE ## ToUV_c(uint8_t *_dstU, uint8_t *_dstV, \
-const uint8_t *_src1, const uint8_t 
*_src2, \
-int width, uint32_t *unused) \
-{ \
-const uint16_t *src1 = (const uint16_t *) _src1, \
-   *src2 = (const uint16_t *) _src2; \
-uint16_t *dstU = (uint16_t *) _dstU, *dstV = (uint16_t *) _dstV; \
-rgb48ToUV_c_template(dstU, dstV, src1, src2, width, origin); \
-} \
- \
-static void pattern ## 48 ## BE_LE ## ToUV_half_c(uint8_t *_dstU, uint8_t 
*_dstV, \
-  

[libav-commits] ARM: allow runtime masking of CPU features

2012-04-22 Thread Mans Rullgard
Module: libav
Branch: master
Commit: d526c5338d50d12a54fd95130030c60070707d3e

Author:Mans Rullgard 
Committer: Mans Rullgard 
Date:  Sat Apr 21 15:31:10 2012 +0100

ARM: allow runtime masking of CPU features

This allows masking CPU features with the -cpuflags avconv option
which is useful for testing different optimisations without rebuilding.

Signed-off-by: Mans Rullgard 

---

 avconv.c   |8 
 libavcodec/arm/ac3dsp_init_arm.c   |8 ++--
 libavcodec/arm/dcadsp_init_arm.c   |6 +-
 libavcodec/arm/dsputil_init_arm.c  |   10 ++
 libavcodec/arm/dsputil_init_vfp.c  |5 -
 libavcodec/arm/fft_fixed_init_arm.c|6 +-
 libavcodec/arm/fft_init_arm.c  |   13 ++---
 libavcodec/arm/fmtconvert_init_arm.c   |7 +--
 libavcodec/arm/h264dsp_init_arm.c  |6 +-
 libavcodec/arm/h264pred_init_arm.c |6 +-
 libavcodec/arm/mpegaudiodsp_init_arm.c |6 +-
 libavcodec/arm/mpegvideo_arm.c |   10 ++
 libavcodec/arm/sbrdsp_init_arm.c   |5 -
 libavcodec/arm/vp56dsp_init_arm.c  |6 +-
 libavcodec/arm/vp8dsp_init_arm.c   |6 +-
 libavutil/arm/Makefile |1 +
 libavutil/arm/cpu.c|   30 ++
 libavutil/arm/cpu.h|   32 
 libavutil/cpu.c|   10 +-
 libavutil/cpu.h|8 
 20 files changed, 164 insertions(+), 25 deletions(-)

diff --git a/avconv.c b/avconv.c
index 6c3e6a9..851d8dd 100644
--- a/avconv.c
+++ b/avconv.c
@@ -4865,6 +4865,14 @@ static int opt_cpuflags(const char *opt, const char *arg)
 { "fma4", NULL, 0, AV_OPT_TYPE_CONST, { CPUFLAG_FMA4 },
.unit = "flags" },
 { "3dnow"   , NULL, 0, AV_OPT_TYPE_CONST, { CPUFLAG_3DNOW},
.unit = "flags" },
 { "3dnowext", NULL, 0, AV_OPT_TYPE_CONST, { CPUFLAG_3DNOWEXT },
.unit = "flags" },
+
+{ "armv5te",  NULL, 0, AV_OPT_TYPE_CONST, { AV_CPU_FLAG_ARMV5TE  },
.unit = "flags" },
+{ "armv6",NULL, 0, AV_OPT_TYPE_CONST, { AV_CPU_FLAG_ARMV6},
.unit = "flags" },
+{ "armv6t2",  NULL, 0, AV_OPT_TYPE_CONST, { AV_CPU_FLAG_ARMV6T2  },
.unit = "flags" },
+{ "vfp",  NULL, 0, AV_OPT_TYPE_CONST, { AV_CPU_FLAG_VFP  },
.unit = "flags" },
+{ "vfpv3",NULL, 0, AV_OPT_TYPE_CONST, { AV_CPU_FLAG_VFPV3},
.unit = "flags" },
+{ "neon", NULL, 0, AV_OPT_TYPE_CONST, { AV_CPU_FLAG_NEON },
.unit = "flags" },
+
 { NULL },
 };
 static const AVClass class = {
diff --git a/libavcodec/arm/ac3dsp_init_arm.c b/libavcodec/arm/ac3dsp_init_arm.c
index aed11f4..d7cb95b 100644
--- a/libavcodec/arm/ac3dsp_init_arm.c
+++ b/libavcodec/arm/ac3dsp_init_arm.c
@@ -19,6 +19,8 @@
  */
 
 #include 
+
+#include "libavutil/arm/cpu.h"
 #include "libavutil/attributes.h"
 #include "libavcodec/ac3dsp.h"
 #include "config.h"
@@ -39,13 +41,15 @@ void ff_ac3_update_bap_counts_arm(uint16_t mant_cnt[16], 
uint8_t *bap, int len);
 
 av_cold void ff_ac3dsp_init_arm(AC3DSPContext *c, int bit_exact)
 {
+int cpu_flags = av_get_cpu_flags();
+
 c->update_bap_counts = ff_ac3_update_bap_counts_arm;
 
-if (HAVE_ARMV6) {
+if (have_armv6(cpu_flags)) {
 c->bit_alloc_calc_bap= ff_ac3_bit_alloc_calc_bap_armv6;
 }
 
-if (HAVE_NEON) {
+if (have_neon(cpu_flags)) {
 c->ac3_exponent_min  = ff_ac3_exponent_min_neon;
 c->ac3_max_msb_abs_int16 = ff_ac3_max_msb_abs_int16_neon;
 c->ac3_lshift_int16  = ff_ac3_lshift_int16_neon;
diff --git a/libavcodec/arm/dcadsp_init_arm.c b/libavcodec/arm/dcadsp_init_arm.c
index ec7016e..f0375c9 100644
--- a/libavcodec/arm/dcadsp_init_arm.c
+++ b/libavcodec/arm/dcadsp_init_arm.c
@@ -19,6 +19,8 @@
  */
 
 #include "config.h"
+
+#include "libavutil/arm/cpu.h"
 #include "libavutil/attributes.h"
 #include "libavcodec/dcadsp.h"
 
@@ -27,6 +29,8 @@ void ff_dca_lfe_fir_neon(float *out, const float *in, const 
float *coefs,
 
 av_cold void ff_dcadsp_init_arm(DCADSPContext *s)
 {
-if (HAVE_NEON)
+int cpu_flags = av_get_cpu_flags();
+
+if (have_neon(cpu_flags))
 s->lfe_fir = ff_dca_lfe_fir_neon;
 }
diff --git a/libavcodec/arm/dsputil_init_arm.c 
b/libavcodec/arm/dsputil_init_arm.c
index bc94b08..0c1563d 100644
--- a/libavcodec/arm/dsputil_init_arm.c
+++ b/libavcodec/arm/dsputil_init_arm.c
@@ -19,6 +19,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "libavutil/arm/cpu.h"
 #include "libavcodec/dsputil.h"
 #include "dsputil_arm.h"
 
@@ -76,6 +77,7 @@ static void simple_idct_arm_add(uint8_t *dest, int line_size, 
DCTELEM *block)
 void ff_dsputil_init_arm(DSPContext* c, AVCodecContext *avctx)
 {
 const int high_bit_depth = avctx->bits_per_raw_sample > 8;
+