[FFmpeg-cvslog] lavc/qsvdec: Add QSV AV1 decoder

2020-09-26 Thread Haihao Xiang
ffmpeg | branch: master | Haihao Xiang  | Wed Sep 16 
15:07:54 2020 +0800| [cc25ae5d8ad2cef2dc8a21b828e89e5077b9dae3] | committer: 
Zhong Li

lavc/qsvdec: Add QSV AV1 decoder

AV1 decoder is supported on Tiger Lake+ platforms since libmfx 1.34

Signed-off-by: Haihao Xiang 
Signed-off-by: Zhong Li 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=cc25ae5d8ad2cef2dc8a21b828e89e5077b9dae3
---

 Changelog |  1 +
 configure |  1 +
 libavcodec/allcodecs.c|  1 +
 libavcodec/qsv.c  |  4 
 libavcodec/qsvdec_other.c | 31 ++-
 5 files changed, 37 insertions(+), 1 deletion(-)

diff --git a/Changelog b/Changelog
index 316da6d145..93beec3720 100644
--- a/Changelog
+++ b/Changelog
@@ -28,6 +28,7 @@ version :
 - DAT demuxer
 - aax demuxer
 - IPU decoder, parser and demuxer
+- Intel QSV-accelerated AV1 decoding
 
 
 version 4.3:
diff --git a/configure b/configure
index 39fabb4ad5..b8de64ccae 100755
--- a/configure
+++ b/configure
@@ -3140,6 +3140,7 @@ vp9_qsv_encoder_deps="libmfx MFX_CODEC_VP9"
 vp9_qsv_encoder_select="qsvenc"
 vp9_v4l2m2m_decoder_deps="v4l2_m2m vp9_v4l2_m2m"
 wmv3_crystalhd_decoder_select="crystalhd"
+av1_qsv_decoder_select="qsvdec"
 
 # parsers
 aac_parser_select="adts_header"
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index 17c88d6290..26fe90eafb 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -821,6 +821,7 @@ extern AVCodec ff_vp9_mediacodec_decoder;
 extern AVCodec ff_vp9_qsv_decoder;
 extern AVCodec ff_vp9_vaapi_encoder;
 extern AVCodec ff_vp9_qsv_encoder;
+extern AVCodec ff_av1_qsv_decoder;
 
 // The iterate API is not usable with ossfuzz due to the excessive size of 
binaries created
 #if CONFIG_OSSFUZZ
diff --git a/libavcodec/qsv.c b/libavcodec/qsv.c
index 17720070f1..7816d2f93c 100644
--- a/libavcodec/qsv.c
+++ b/libavcodec/qsv.c
@@ -64,6 +64,10 @@ int ff_qsv_codec_id_to_mfx(enum AVCodecID codec_id)
 case AV_CODEC_ID_VP9:
 return MFX_CODEC_VP9;
 #endif
+#if QSV_VERSION_ATLEAST(1, 34)
+case AV_CODEC_ID_AV1:
+return MFX_CODEC_AV1;
+#endif
 
 default:
 break;
diff --git a/libavcodec/qsvdec_other.c b/libavcodec/qsvdec_other.c
index b4df76739c..2775e07955 100644
--- a/libavcodec/qsvdec_other.c
+++ b/libavcodec/qsvdec_other.c
@@ -1,5 +1,5 @@
 /*
- * Intel MediaSDK QSV based MPEG-2, VC-1, VP8, MJPEG and VP9 decoders
+ * Intel MediaSDK QSV based MPEG-2, VC-1, VP8, MJPEG, VP9 and AV1 decoders
  *
  * copyright (c) 2015 Anton Khirnov
  *
@@ -327,3 +327,32 @@ AVCodec ff_vp9_qsv_decoder = {
 .wrapper_name   = "qsv",
 };
 #endif
+
+#if CONFIG_AV1_QSV_DECODER
+static const AVClass av1_qsv_class = {
+.class_name = "av1_qsv",
+.item_name  = av_default_item_name,
+.option = options,
+.version= LIBAVUTIL_VERSION_INT,
+};
+
+AVCodec ff_av1_qsv_decoder = {
+.name   = "av1_qsv",
+.long_name  = NULL_IF_CONFIG_SMALL("AV1 video (Intel Quick Sync Video 
acceleration)"),
+.priv_data_size = sizeof(QSVOtherContext),
+.type   = AVMEDIA_TYPE_VIDEO,
+.id = AV_CODEC_ID_AV1,
+.init   = qsv_decode_init,
+.decode = qsv_decode_frame,
+.flush  = qsv_decode_flush,
+.close  = qsv_decode_close,
+.capabilities   = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_DR1 | 
AV_CODEC_CAP_AVOID_PROBING | AV_CODEC_CAP_HYBRID,
+.priv_class = &av1_qsv_class,
+.pix_fmts   = (const enum AVPixelFormat[]){ AV_PIX_FMT_NV12,
+AV_PIX_FMT_P010,
+AV_PIX_FMT_QSV,
+AV_PIX_FMT_NONE },
+.hw_configs = ff_qsv_hw_configs,
+.wrapper_name   = "qsv",
+};
+#endif

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

To unsubscribe, visit link above, or email
ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-cvslog] avcodec/dxtory: Fix get_raw_size() for YUV

2020-09-26 Thread Michael Niedermayer
ffmpeg | branch: master | Michael Niedermayer  | Fri 
Sep 25 17:07:24 2020 +0200| [497debb171b866500ef428479139a112ee7e50d8] | 
committer: Michael Niedermayer

avcodec/dxtory: Fix get_raw_size() for YUV

Fixes: out of array read
Fixes: 
25455/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_DXTORY_fuzzer-6327985731534848

Found-by: continuous fuzzing process 
https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Reviewed-by: Paul B Mahol 
Signed-off-by: Michael Niedermayer 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=497debb171b866500ef428479139a112ee7e50d8
---

 libavcodec/dxtory.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavcodec/dxtory.c b/libavcodec/dxtory.c
index 3f3c23ff2a..157e4b3ed2 100644
--- a/libavcodec/dxtory.c
+++ b/libavcodec/dxtory.c
@@ -44,9 +44,9 @@ static int64_t get_raw_size(enum AVPixelFormat fmt, int 
width, int height)
 case AV_PIX_FMT_YUV444P:
 return width * height * 3LL;
 case AV_PIX_FMT_YUV420P:
-return (int64_t)(width * height) + AV_CEIL_RSHIFT(width, 1) * 
AV_CEIL_RSHIFT(height, 1);
+return (int64_t)(width * height) + 2 * AV_CEIL_RSHIFT(width, 1) * 
AV_CEIL_RSHIFT(height, 1);
 case AV_PIX_FMT_YUV410P:
-return (int64_t)(width * height) + AV_CEIL_RSHIFT(width, 2) * 
AV_CEIL_RSHIFT(height, 2);
+return (int64_t)(width * height) + 2 * AV_CEIL_RSHIFT(width, 2) * 
AV_CEIL_RSHIFT(height, 2);
 }
 
 return 0;

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

To unsubscribe, visit link above, or email
ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-cvslog] avcodec/dxtory: Fix negative shift in dxtory_decode_v1_410()

2020-09-26 Thread Michael Niedermayer
ffmpeg | branch: master | Michael Niedermayer  | Fri 
Sep 25 17:15:29 2020 +0200| [c3d1c7f903892455161fa1f722e01a7eaf2c6451] | 
committer: Michael Niedermayer

avcodec/dxtory: Fix negative shift in dxtory_decode_v1_410()

Fixes: left shift of negative value -256
Fixes: 
25460/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_DXTORY_fuzzer-5073252341514240

Found-by: continuous fuzzing process 
https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Reviewed-by: Paul B Mahol 
Signed-off-by: Michael Niedermayer 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=c3d1c7f903892455161fa1f722e01a7eaf2c6451
---

 libavcodec/dxtory.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/libavcodec/dxtory.c b/libavcodec/dxtory.c
index 157e4b3ed2..a82532c467 100644
--- a/libavcodec/dxtory.c
+++ b/libavcodec/dxtory.c
@@ -177,10 +177,10 @@ static int dxtory_decode_v1_410(AVCodecContext *avctx, 
AVFrame *pic,
 V[huvborder] = src[1] + 0x80;
 src += 2;
 }
-Y1 += pic->linesize[0] << 2;
-Y2 += pic->linesize[0] << 2;
-Y3 += pic->linesize[0] << 2;
-Y4 += pic->linesize[0] << 2;
+Y1 += pic->linesize[0] * 4;
+Y2 += pic->linesize[0] * 4;
+Y3 += pic->linesize[0] * 4;
+Y4 += pic->linesize[0] * 4;
 U  += pic->linesize[1];
 V  += pic->linesize[2];
 }

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

To unsubscribe, visit link above, or email
ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-cvslog] avcodec/dxtory: Fix negative shift in dx2_decode_slice_410()

2020-09-26 Thread Michael Niedermayer
ffmpeg | branch: master | Michael Niedermayer  | Fri 
Sep 25 20:08:37 2020 +0200| [abebd87764992dc22c82802bdc75d40aac14ab86] | 
committer: Michael Niedermayer

avcodec/dxtory: Fix negative shift in dx2_decode_slice_410()

Fixes: left shift of negative value -768
Fixes: 
25574/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_DXTORY_fuzzer-6012596027916288

Found-by: continuous fuzzing process 
https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Reviewed-by: Paul B Mahol 
Signed-off-by: Michael Niedermayer 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=abebd87764992dc22c82802bdc75d40aac14ab86
---

 libavcodec/dxtory.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/dxtory.c b/libavcodec/dxtory.c
index a82532c467..bc95e0e7e1 100644
--- a/libavcodec/dxtory.c
+++ b/libavcodec/dxtory.c
@@ -637,7 +637,7 @@ static int dx2_decode_slice_410(GetBitContext *gb, AVFrame 
*frame,
 V[huvborder] = decode_sym(gb, lru[2]) ^ 0x80;
 }
 
-Y += ystride << 2;
+Y += ystride * 4;
 U += ustride;
 V += vstride;
 }

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

To unsubscribe, visit link above, or email
ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-cvslog] avcodec/magicyuv: Check early for invalid slices

2020-09-26 Thread Andreas Rheinhardt
ffmpeg | branch: master | Andreas Rheinhardt  | 
Wed Sep 23 06:24:03 2020 +0200| [3c172a2fb91a758d9e15f09f96879e6e9b5a37ec] | 
committer: Andreas Rheinhardt

avcodec/magicyuv: Check early for invalid slices

Every plane of each slice has to contain at least two bytes for flags
and the type of prediction used.

Reviewed-by: Paul B Mahol 
Signed-off-by: Andreas Rheinhardt 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=3c172a2fb91a758d9e15f09f96879e6e9b5a37ec
---

 libavcodec/magicyuv.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/libavcodec/magicyuv.c b/libavcodec/magicyuv.c
index d2f6a9b01e..6c29efc9f4 100644
--- a/libavcodec/magicyuv.c
+++ b/libavcodec/magicyuv.c
@@ -614,6 +614,8 @@ static int magy_decode_frame(AVCodecContext *avctx, void 
*data,
 return AVERROR_INVALIDDATA;
 
 s->slices[i][j].size = next_offset - offset;
+if (s->slices[i][j].size < 2)
+return AVERROR_INVALIDDATA;
 offset = next_offset;
 }
 

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

To unsubscribe, visit link above, or email
ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-cvslog] avcodec/magicyuv: Improve overread check when parsing Huffman tables

2020-09-26 Thread Andreas Rheinhardt
ffmpeg | branch: master | Andreas Rheinhardt  | 
Wed Sep 23 05:42:31 2020 +0200| [85737a4d76f8a39ec5554abe62bcbc41b6123d09] | 
committer: Andreas Rheinhardt

avcodec/magicyuv: Improve overread check when parsing Huffman tables

Reviewed-by: Paul B Mahol 
Signed-off-by: Andreas Rheinhardt 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=85737a4d76f8a39ec5554abe62bcbc41b6123d09
---

 libavcodec/magicyuv.c | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/libavcodec/magicyuv.c b/libavcodec/magicyuv.c
index b56d3e9d32..d2f6a9b01e 100644
--- a/libavcodec/magicyuv.c
+++ b/libavcodec/magicyuv.c
@@ -394,8 +394,13 @@ static int build_huffman(AVCodecContext *avctx, 
GetBitContext *gbit, int max)
 while (get_bits_left(gbit) >= 8) {
 int b = get_bits(gbit, 1);
 int x = get_bits(gbit, 7);
-int l = get_bitsz(gbit, b * 8) + 1;
+int l = 1;
 
+if (b) {
+if (get_bits_left(gbit) < 8)
+break;
+l += get_bits(gbit, 8);
+}
 k = j + l;
 if (k > max || x == 0 || x > 32) {
 av_log(avctx, AV_LOG_ERROR, "Invalid Huffman codes\n");

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

To unsubscribe, visit link above, or email
ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-cvslog] avcodec/magicyuv: Use const uint8_t* for pointer to immutable data

2020-09-26 Thread Andreas Rheinhardt
ffmpeg | branch: master | Andreas Rheinhardt  | 
Wed Sep 23 08:00:24 2020 +0200| [08e5597d2f139edda8920444a04a1b155f8a3a03] | 
committer: Andreas Rheinhardt

avcodec/magicyuv: Use const uint8_t* for pointer to immutable data

Reviewed-by: Paul B Mahol 
Signed-off-by: Andreas Rheinhardt 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=08e5597d2f139edda8920444a04a1b155f8a3a03
---

 libavcodec/magicyuv.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/magicyuv.c b/libavcodec/magicyuv.c
index f7dfef0eb8..3413d8f298 100644
--- a/libavcodec/magicyuv.c
+++ b/libavcodec/magicyuv.c
@@ -63,7 +63,7 @@ typedef struct MagicYUVContext {
 int   color_matrix;   // video color matrix
 int   flags;
 int   interlaced; // video is interlaced
-uint8_t  *buf;// pointer to AVPacket->data
+const uint8_t*buf;// pointer to AVPacket->data
 int   hshift[4];
 int   vshift[4];
 Slice*slices[4];  // slice bitstream positions for each 
plane

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

To unsubscribe, visit link above, or email
ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-cvslog] avcodec/magicyuv: Don't use GetBit API for byte-aligned reads

2020-09-26 Thread Andreas Rheinhardt
ffmpeg | branch: master | Andreas Rheinhardt  | 
Wed Sep 23 06:42:24 2020 +0200| [bf31b451559323776daa59003edbe9cbeed5bd91] | 
committer: Andreas Rheinhardt

avcodec/magicyuv: Don't use GetBit API for byte-aligned reads

Reviewed-by: Paul B Mahol 
Signed-off-by: Andreas Rheinhardt 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=bf31b451559323776daa59003edbe9cbeed5bd91
---

 libavcodec/magicyuv.c | 45 ++---
 1 file changed, 22 insertions(+), 23 deletions(-)

diff --git a/libavcodec/magicyuv.c b/libavcodec/magicyuv.c
index 6c29efc9f4..f7dfef0eb8 100644
--- a/libavcodec/magicyuv.c
+++ b/libavcodec/magicyuv.c
@@ -270,27 +270,26 @@ static int magy_decode_slice(AVCodecContext *avctx, void 
*tdata,
 int sheight = AV_CEIL_RSHIFT(s->slice_height, s->vshift[i]);
 ptrdiff_t fake_stride = p->linesize[i] * (1 + interlaced);
 ptrdiff_t stride = p->linesize[i];
+const uint8_t *slice = s->buf + s->slices[i][j].start;
 int flags, pred;
-int ret = init_get_bits8(&gb, s->buf + s->slices[i][j].start,
- s->slices[i][j].size);
-
-if (ret < 0)
-return ret;
 
-flags = get_bits(&gb, 8);
-pred  = get_bits(&gb, 8);
+flags = bytestream_get_byte(&slice);
+pred  = bytestream_get_byte(&slice);
 
 dst = p->data[i] + j * sheight * stride;
 if (flags & 1) {
-if (get_bits_left(&gb) < 8* width * height)
+if (s->slices[i][j].size - 2 < width * height)
 return AVERROR_INVALIDDATA;
 for (k = 0; k < height; k++) {
-for (x = 0; x < width; x++)
-dst[x] = get_bits(&gb, 8);
-
+bytestream_get_buffer(&slice, dst, width);
 dst += stride;
 }
 } else {
+int ret = init_get_bits8(&gb, slice, s->slices[i][j].size - 2);
+
+if (ret < 0)
+return ret;
+
 for (k = 0; k < height; k++) {
 for (x = 0; x < width; x++) {
 int pix;
@@ -385,21 +384,25 @@ static int magy_decode_slice(AVCodecContext *avctx, void 
*tdata,
 return 0;
 }
 
-static int build_huffman(AVCodecContext *avctx, GetBitContext *gbit, int max)
+static int build_huffman(AVCodecContext *avctx, const uint8_t *table,
+ int table_size, int max)
 {
 MagicYUVContext *s = avctx->priv_data;
+GetByteContext gb;
 HuffEntry he[4096];
 int i = 0, j = 0, k;
 
-while (get_bits_left(gbit) >= 8) {
-int b = get_bits(gbit, 1);
-int x = get_bits(gbit, 7);
+bytestream2_init(&gb, table, table_size);
+
+while (bytestream2_get_bytes_left(&gb) > 0) {
+int b = bytestream2_peek_byteu(&gb) &  0x80;
+int x = bytestream2_get_byteu(&gb)  & ~0x80;
 int l = 1;
 
 if (b) {
-if (get_bits_left(gbit) < 8)
+if (bytestream2_get_bytes_left(&gb) <= 0)
 break;
-l += get_bits(gbit, 8);
+l += bytestream2_get_byteu(&gb);
 }
 k = j + l;
 if (k > max || x == 0 || x > 32) {
@@ -440,7 +443,6 @@ static int magy_decode_frame(AVCodecContext *avctx, void 
*data,
 ThreadFrame frame = { .f = data };
 AVFrame *p = data;
 GetByteContext gbyte;
-GetBitContext gbit;
 uint32_t first_offset, offset, next_offset, header_size, slice_width;
 int width, height, format, version, table_size;
 int ret, i, j;
@@ -632,11 +634,8 @@ static int magy_decode_frame(AVCodecContext *avctx, void 
*data,
 if (table_size < 2)
 return AVERROR_INVALIDDATA;
 
-ret = init_get_bits8(&gbit, avpkt->data + bytestream2_tell(&gbyte), 
table_size);
-if (ret < 0)
-return ret;
-
-ret = build_huffman(avctx, &gbit, s->max);
+ret = build_huffman(avctx, avpkt->data + bytestream2_tell(&gbyte),
+table_size, s->max);
 if (ret < 0)
 return ret;
 

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

To unsubscribe, visit link above, or email
ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-cvslog] avcodec/diracdsp: Remove unused variable

2020-09-26 Thread Andreas Rheinhardt
ffmpeg | branch: master | Andreas Rheinhardt  | 
Wed Sep 23 20:20:12 2020 +0200| [310d4062e7639217d717e447426343366775ac30] | 
committer: Andreas Rheinhardt

avcodec/diracdsp: Remove unused variable

Forgotten in ca3c6c981aa5b0af8a5576020b79fdd3cdf9ae9e.

Reviewed-by: Paul B Mahol 
Signed-off-by: Andreas Rheinhardt 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=310d4062e7639217d717e447426343366775ac30
---

 libavcodec/diracdsp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/diracdsp.c b/libavcodec/diracdsp.c
index 4e08d3817e..80dfafd78b 100644
--- a/libavcodec/diracdsp.c
+++ b/libavcodec/diracdsp.c
@@ -195,7 +195,7 @@ static void dequant_subband_ ## PX ## _c(uint8_t *src, 
uint8_t *dst, ptrdiff_t s
 {  
\
 int i, y;  
\
 for (y = 0; y < tot_v; y++) {  
\
-PX c, sign, *src_r = (PX *)src, *dst_r = (PX *)dst;
\
+PX c, *src_r = (PX *)src, *dst_r = (PX *)dst;  
\
 for (i = 0; i < tot_h; i++) {  
\
 c = *src_r++;  
\
 if (c < 0) c = -((-(unsigned)c*qf + qs) >> 2); 
\

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

To unsubscribe, visit link above, or email
ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-cvslog] avcodec/photocd: Simplify parsing Huffman tables a bit

2020-09-26 Thread Andreas Rheinhardt
ffmpeg | branch: master | Andreas Rheinhardt  | 
Wed Sep 23 04:57:53 2020 +0200| [a902c24994dea7cbdf84bff70ad8709958b1008d] | 
committer: Andreas Rheinhardt

avcodec/photocd: Simplify parsing Huffman tables a bit

Reviewed-by: Paul B Mahol 
Signed-off-by: Andreas Rheinhardt 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=a902c24994dea7cbdf84bff70ad8709958b1008d
---

 libavcodec/photocd.c | 13 ++---
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/libavcodec/photocd.c b/libavcodec/photocd.c
index 057c9d33d4..8fd4536a65 100644
--- a/libavcodec/photocd.c
+++ b/libavcodec/photocd.c
@@ -245,21 +245,20 @@ static av_noinline int decode_huff(AVCodecContext *avctx, 
AVFrame *frame,
 int x2, idx;
 
 for (; get_bits_left(&g) > 0;) {
-if ((show_bits(&g, 24) & 0xfff000) == 0xfff000)
+if (show_bits(&g, 12) == 0xfff)
 break;
 skip_bits(&g, 8);
 }
 
-shiftreg = show_bits_long(&g, 32) & 0xff00;
-while (shiftreg != 0xfe00) {
+shiftreg = show_bits(&g, 24);
+while (shiftreg != 0xfe) {
 if (get_bits_left(&g) <= 0)
 return AVERROR_INVALIDDATA;
 skip_bits(&g, 1);
-shiftreg = show_bits_long(&g, 32) & 0xff00;
+shiftreg = show_bits(&g, 24);
 }
-skip_bits(&g, 16);
-y = show_bits_long(&g, 23) & 0x1fff;
-skip_bits(&g, 8);
+skip_bits(&g, 24);
+y = show_bits(&g, 15) & 0x1fff;
 if (y >= height)
 break;
 type = get_bits(&g, 2);

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

To unsubscribe, visit link above, or email
ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-cvslog] avcodec/magicyuv: Replace implicit checks for overread by explicit ones

2020-09-26 Thread Andreas Rheinhardt
ffmpeg | branch: master | Andreas Rheinhardt  | 
Wed Sep 23 08:28:59 2020 +0200| [157953066ccd8cdaeecbf17ad694a82a8dd22145] | 
committer: Andreas Rheinhardt

avcodec/magicyuv: Replace implicit checks for overread by explicit ones

Reviewed-by: Paul B Mahol 
Signed-off-by: Andreas Rheinhardt 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=157953066ccd8cdaeecbf17ad694a82a8dd22145
---

 libavcodec/magicyuv.c | 49 +++--
 1 file changed, 27 insertions(+), 22 deletions(-)

diff --git a/libavcodec/magicyuv.c b/libavcodec/magicyuv.c
index 3413d8f298..93ee739093 100644
--- a/libavcodec/magicyuv.c
+++ b/libavcodec/magicyuv.c
@@ -442,23 +442,26 @@ static int magy_decode_frame(AVCodecContext *avctx, void 
*data,
 MagicYUVContext *s = avctx->priv_data;
 ThreadFrame frame = { .f = data };
 AVFrame *p = data;
-GetByteContext gbyte;
+GetByteContext gb;
 uint32_t first_offset, offset, next_offset, header_size, slice_width;
 int width, height, format, version, table_size;
 int ret, i, j;
 
-bytestream2_init(&gbyte, avpkt->data, avpkt->size);
-if (bytestream2_get_le32(&gbyte) != MKTAG('M', 'A', 'G', 'Y'))
+if (avpkt->size < 36)
+return AVERROR_INVALIDDATA;
+
+bytestream2_init(&gb, avpkt->data, avpkt->size);
+if (bytestream2_get_le32u(&gb) != MKTAG('M', 'A', 'G', 'Y'))
 return AVERROR_INVALIDDATA;
 
-header_size = bytestream2_get_le32(&gbyte);
+header_size = bytestream2_get_le32u(&gb);
 if (header_size < 32 || header_size >= avpkt->size) {
 av_log(avctx, AV_LOG_ERROR,
"header or packet too small %"PRIu32"\n", header_size);
 return AVERROR_INVALIDDATA;
 }
 
-version = bytestream2_get_byte(&gbyte);
+version = bytestream2_get_byteu(&gb);
 if (version != 7) {
 avpriv_request_sample(avctx, "Version %d", version);
 return AVERROR_PATCHWELCOME;
@@ -471,7 +474,7 @@ static int magy_decode_frame(AVCodecContext *avctx, void 
*data,
 s->decorrelate = 0;
 s->bps = 8;
 
-format = bytestream2_get_byte(&gbyte);
+format = bytestream2_get_byteu(&gb);
 switch (format) {
 case 0x65:
 avctx->pix_fmt = AV_PIX_FMT_GBRP;
@@ -552,34 +555,34 @@ static int magy_decode_frame(AVCodecContext *avctx, void 
*data,
 s->magy_decode_slice = s->bps == 8 ? magy_decode_slice : 
magy_decode_slice10;
 s->planes = av_pix_fmt_count_planes(avctx->pix_fmt);
 
-bytestream2_skip(&gbyte, 1);
-s->color_matrix = bytestream2_get_byte(&gbyte);
-s->flags= bytestream2_get_byte(&gbyte);
+bytestream2_skipu(&gb, 1);
+s->color_matrix = bytestream2_get_byteu(&gb);
+s->flags= bytestream2_get_byteu(&gb);
 s->interlaced   = !!(s->flags & 2);
-bytestream2_skip(&gbyte, 3);
+bytestream2_skipu(&gb, 3);
 
-width  = bytestream2_get_le32(&gbyte);
-height = bytestream2_get_le32(&gbyte);
+width  = bytestream2_get_le32u(&gb);
+height = bytestream2_get_le32u(&gb);
 ret = ff_set_dimensions(avctx, width, height);
 if (ret < 0)
 return ret;
 
-slice_width = bytestream2_get_le32(&gbyte);
+slice_width = bytestream2_get_le32u(&gb);
 if (slice_width != avctx->coded_width) {
 avpriv_request_sample(avctx, "Slice width %"PRIu32, slice_width);
 return AVERROR_PATCHWELCOME;
 }
-s->slice_height = bytestream2_get_le32(&gbyte);
+s->slice_height = bytestream2_get_le32u(&gb);
 if (s->slice_height <= 0 || s->slice_height > INT_MAX - 
avctx->coded_height) {
 av_log(avctx, AV_LOG_ERROR,
"invalid slice height: %d\n", s->slice_height);
 return AVERROR_INVALIDDATA;
 }
 
-bytestream2_skip(&gbyte, 4);
+bytestream2_skipu(&gb, 4);
 
 s->nb_slices = (avctx->coded_height + s->slice_height - 1) / 
s->slice_height;
-if (s->nb_slices > INT_MAX / sizeof(Slice)) {
+if (s->nb_slices > INT_MAX / FFMAX(sizeof(Slice), 4 * 5)) {
 av_log(avctx, AV_LOG_ERROR,
"invalid number of slices: %d\n", s->nb_slices);
 return AVERROR_INVALIDDATA;
@@ -596,12 +599,14 @@ static int magy_decode_frame(AVCodecContext *avctx, void 
*data,
 }
 }
 
+if (bytestream2_get_bytes_left(&gb) <= s->nb_slices * s->planes * 5)
+return AVERROR_INVALIDDATA;
 for (i = 0; i < s->planes; i++) {
 av_fast_malloc(&s->slices[i], &s->slices_size[i], s->nb_slices * 
sizeof(Slice));
 if (!s->slices[i])
 return AVERROR(ENOMEM);
 
-offset = bytestream2_get_le32(&gbyte);
+offset = bytestream2_get_le32u(&gb);
 if (offset >= avpkt->size - header_size)
 return AVERROR_INVALIDDATA;
 
@@ -611,7 +616,7 @@ static int magy_decode_frame(AVCodecContext *avctx, void 
*data,
 for (j = 0; j < s->nb_slices - 1; j++) {
 s->slices[i][j].start = offset + header_size;
 
-next_offset = bytestream2_get_le32(&gbyte);
+

[FFmpeg-cvslog] avcodec/magicyuv: Fix edge case of building Huffman table

2020-09-26 Thread Andreas Rheinhardt
ffmpeg | branch: master | Andreas Rheinhardt  | 
Wed Sep 23 14:33:38 2020 +0200| [59f7d685141d724d6ef845a9c0f81106eb87771c] | 
committer: Andreas Rheinhardt

avcodec/magicyuv: Fix edge case of building Huffman table

The MagicYUV format stores Huffman tables in its bitstream by coding
the length of a given symbol; it does not code the actual code directly,
instead this is to be inferred by the rule that a symbol is to the left
of every shorter symbol in the Huffman tree and that for symbols of the
same length the symbol is ascending from left to right. With one
exception, this is also what our decoder did.

The exception only matters when there are codes of length 32, because
in this case the first symbol of this length did not get the code 0,
but 1; e.g. if there were exactly two nodes of length 32, then they
would get assigned the codes 1 and 2 and a node of length 31 will get
the 31-bit code 1 which is a prefix of the 32 bit code 2, making the
Huffman table invalid. On the other hand, if there were only one symbol
with the length 32, the earlier code would accept this un-Huffman-tree.

Reviewed-by: Paul B Mahol 
Signed-off-by: Andreas Rheinhardt 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=59f7d685141d724d6ef845a9c0f81106eb87771c
---

 libavcodec/magicyuv.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/magicyuv.c b/libavcodec/magicyuv.c
index 1b3f4cfc6b..17dea69d76 100644
--- a/libavcodec/magicyuv.c
+++ b/libavcodec/magicyuv.c
@@ -86,7 +86,7 @@ static int huff_build(HuffEntry he[], VLC *vlc, int nb_elems)
 
 AV_QSORT(he, nb_elems, HuffEntry, huff_cmp_len);
 
-code = 1;
+code = 0;
 for (unsigned i = 0; i < nb_elems; i++) {
 he[i].code = code >> (32 - he[i].len);
 code += 0x8000u >> (he[i].len - 1);

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

To unsubscribe, visit link above, or email
ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-cvslog] avcodec/magicyuv: Avoid AV_QSORT when creating Huffman table

2020-09-26 Thread Andreas Rheinhardt
ffmpeg | branch: master | Andreas Rheinhardt  | 
Wed Sep 23 15:17:33 2020 +0200| [1bf30a1beb7527887c9b466d07765d20fa3b5412] | 
committer: Andreas Rheinhardt

avcodec/magicyuv: Avoid AV_QSORT when creating Huffman table

The MagicYUV format stores Huffman tables in its bitstream by coding
the length of a given symbol; it does not code the actual code directly,
instead this is to be inferred by the rule that a symbol is to the left
of every shorter symbol in the Huffman tree and that for symbols of the
same length the symbol is ascending from left to right.

Our decoder implemented this by first sorting the array containing
length and symbol of each element according to descending length and
for equal length, according to ascending symbol. Afterwards, the current
state in the tree got encoded in a variable code; if the next array entry
had length len, then the len most significant bits of code contained
the code of this entry. Whenever an entry of the array of length
len was processed, code was incremented by 1U << (32 - len). So two
entries of length len have the same effect as incrementing code by
1U << (32 - (len - 1)), which corresponds to the parent node of length
len - 1 of the two nodes of length len etc.

This commit modifies this to avoid sorting the entries before
calculating the codes. This is done by calculating how many non-leaf
nodes there are on each level of the tree before calculating the codes.
Afterwards every leaf node on this level gets assigned the number of
nodes already on this level as code. This of course works only because
the entries are already sorted by their symbol initially, so that this
algorithm indeed gives ascending symbols from left to right on every
level.

This offers both speed- as well as (obvious) codesize advantages. With
Clang 10 the number of decicycles for build_huffman decreased from
1561987 to 1228405; for GCC 9 it went from 1825096 decicyles to 1429921.
These tests were carried out with a sample with 150 frames that was
looped 13 times; and this was iterated 10 times. The earlier reference
point here is from the point when the loop generating the codes was
traversed in reverse order (as the patch reversing the order led to
performance penalties).

Reviewed-by: Paul B Mahol 
Signed-off-by: Andreas Rheinhardt 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=1bf30a1beb7527887c9b466d07765d20fa3b5412
---

 libavcodec/magicyuv.c | 36 ++--
 1 file changed, 18 insertions(+), 18 deletions(-)

diff --git a/libavcodec/magicyuv.c b/libavcodec/magicyuv.c
index 17dea69d76..7dded9b457 100644
--- a/libavcodec/magicyuv.c
+++ b/libavcodec/magicyuv.c
@@ -25,7 +25,6 @@
 #define CACHED_BITSTREAM_READER !ARCH_X86_32
 
 #include "libavutil/pixdesc.h"
-#include "libavutil/qsort.h"
 
 #include "avcodec.h"
 #include "bytestream.h"
@@ -74,26 +73,24 @@ typedef struct MagicYUVContext {
 LLVidDSPContext   llviddsp;
 } MagicYUVContext;
 
-static int huff_cmp_len(const void *a, const void *b)
+static int huff_build(HuffEntry he[], uint16_t codes_count[33],
+  VLC *vlc, int nb_elems)
 {
-const HuffEntry *aa = a, *bb = b;
-return (bb->len - aa->len) * 4096 + aa->sym - bb->sym;
-}
-
-static int huff_build(HuffEntry he[], VLC *vlc, int nb_elems)
-{
-uint32_t code;
-
-AV_QSORT(he, nb_elems, HuffEntry, huff_cmp_len);
+unsigned nb_codes = 0, max = 0;
+
+for (int i = 32; i > 0; i--) {
+uint16_t curr = codes_count[i];   // # of leafs of length i
+codes_count[i] = nb_codes / 2;// # of non-leaf nodes on level i
+nb_codes = codes_count[i] + curr; // # of nodes on level i
+if (curr && !max)
+max = i;
+}
 
-code = 0;
 for (unsigned i = 0; i < nb_elems; i++) {
-he[i].code = code >> (32 - he[i].len);
-code += 0x8000u >> (he[i].len - 1);
+he[i].code = codes_count[he[i].len];
+codes_count[he[i].len]++;
 }
-
-ff_free_vlc(vlc);
-return ff_init_vlc_sparse(vlc, FFMIN(he[0].len, 12), nb_elems,
+return ff_init_vlc_sparse(vlc, FFMIN(max, 12), nb_elems,
   &he[0].len,  sizeof(he[0]), sizeof(he[0].len),
   &he[0].code, sizeof(he[0]), sizeof(he[0].code),
   &he[0].sym,  sizeof(he[0]), sizeof(he[0].sym),  
0);
@@ -389,6 +386,7 @@ static int build_huffman(AVCodecContext *avctx, const 
uint8_t *table,
 MagicYUVContext *s = avctx->priv_data;
 GetByteContext gb;
 HuffEntry he[4096];
+uint16_t length_count[33] = { 0 };
 int i = 0, j = 0, k;
 
 bytestream2_init(&gb, table, table_size);
@@ -409,6 +407,7 @@ static int build_huffman(AVCodecContext *avctx, const 
uint8_t *table,
 return AVERROR_INVALIDDATA;
 }
 
+length_count[x] += l;
 for (; j < k; j++) {
 he[j].sym = j;
 he[j].len = x;
@@ -416,7 +415,7 @@ static int build_huffman(AVCodecContext *avctx, const 
ui

[FFmpeg-cvslog] avcodec/bytestream: Add unchecked bytestream2 peek functions

2020-09-26 Thread Andreas Rheinhardt
ffmpeg | branch: master | Andreas Rheinhardt  | 
Thu May 28 17:43:56 2020 +0200| [94dc3385e498ee408275fdf9107b995afa917115] | 
committer: Andreas Rheinhardt

avcodec/bytestream: Add unchecked bytestream2 peek functions

Reviewed-by: Paul B Mahol 
Signed-off-by: Andreas Rheinhardt 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=94dc3385e498ee408275fdf9107b995afa917115
---

 libavcodec/bytestream.h | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/libavcodec/bytestream.h b/libavcodec/bytestream.h
index 0516a6e3dc..d0033f14f3 100644
--- a/libavcodec/bytestream.h
+++ b/libavcodec/bytestream.h
@@ -77,11 +77,15 @@ static av_always_inline type bytestream2_get_ ## 
name(GetByteContext *g)   \
 }  
\
 return bytestream2_get_ ## name ## u(g);   
\
 }  
\
+static av_always_inline type bytestream2_peek_ ## name ## u(GetByteContext *g) 
\
+{  
\
+return read(g->buffer);
\
+}  
\
 static av_always_inline type bytestream2_peek_ ## name(GetByteContext *g)  
\
 {  
\
 if (g->buffer_end - g->buffer < bytes) 
\
 return 0;  
\
-return read(g->buffer);
\
+return bytestream2_peek_ ## name ## u(g);  
\
 }
 
 DEF(uint64_t, le64, 8, AV_RL64, AV_WL64)

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

To unsubscribe, visit link above, or email
ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-cvslog] avcodec/utvideo: Move stuff only used by Ut encoder to Ut encoder

2020-09-26 Thread Andreas Rheinhardt
ffmpeg | branch: master | Andreas Rheinhardt  | 
Thu Sep 24 18:43:11 2020 +0200| [bb16dbc0026c43d3aba6d803bb0a968ece25ba2b] | 
committer: Andreas Rheinhardt

avcodec/utvideo: Move stuff only used by Ut encoder to Ut encoder

Reviewed-by: Paul B Mahol 
Signed-off-by: Andreas Rheinhardt 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=bb16dbc0026c43d3aba6d803bb0a968ece25ba2b
---

 libavcodec/Makefile |  4 ++--
 libavcodec/utvideo.c| 39 ---
 libavcodec/utvideo.h| 12 
 libavcodec/utvideoenc.c | 23 +--
 4 files changed, 23 insertions(+), 55 deletions(-)

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 9b120a6f64..bee2335a5a 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -664,8 +664,8 @@ OBJS-$(CONFIG_TTA_ENCODER) += ttaenc.o 
ttaencdsp.o ttadata.o
 OBJS-$(CONFIG_TWINVQ_DECODER)  += twinvqdec.o twinvq.o
 OBJS-$(CONFIG_TXD_DECODER) += txd.o
 OBJS-$(CONFIG_ULTI_DECODER)+= ulti.o
-OBJS-$(CONFIG_UTVIDEO_DECODER) += utvideodec.o utvideo.o utvideodsp.o
-OBJS-$(CONFIG_UTVIDEO_ENCODER) += utvideoenc.o utvideo.o
+OBJS-$(CONFIG_UTVIDEO_DECODER) += utvideodec.o utvideodsp.o
+OBJS-$(CONFIG_UTVIDEO_ENCODER) += utvideoenc.o
 OBJS-$(CONFIG_V210_DECODER)+= v210dec.o
 OBJS-$(CONFIG_V210_ENCODER)+= v210enc.o
 OBJS-$(CONFIG_V210X_DECODER)   += v210x.o
diff --git a/libavcodec/utvideo.c b/libavcodec/utvideo.c
deleted file mode 100644
index 0cf0cbcd8b..00
--- a/libavcodec/utvideo.c
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Common Ut Video code
- * Copyright (c) 2011 Konstantin Shishkov
- *
- * This file is part of FFmpeg.
- *
- * FFmpeg 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.
- *
- * FFmpeg 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 FFmpeg; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-/**
- * @file
- * Common Ut Video code
- */
-
-#include "utvideo.h"
-
-#if FF_API_PRIVATE_OPT
-const int ff_ut_pred_order[5] = {
-PRED_LEFT, PRED_MEDIAN, PRED_MEDIAN, PRED_NONE, PRED_GRADIENT
-};
-#endif
-
-int ff_ut_huff_cmp_len(const void *a, const void *b)
-{
-const HuffEntry *aa = a, *bb = b;
-return (aa->len - bb->len)*256 + aa->sym - bb->sym;
-}
diff --git a/libavcodec/utvideo.h b/libavcodec/utvideo.h
index 2975f287a7..9da9329ff3 100644
--- a/libavcodec/utvideo.h
+++ b/libavcodec/utvideo.h
@@ -61,9 +61,6 @@ enum {
 UTVIDEO_444  = MKTAG('Y', 'V', '2', '4'),
 };
 
-/* Mapping of libavcodec prediction modes to Ut Video's */
-extern const int ff_ut_pred_order[5];
-
 typedef struct UtvideoContext {
 const AVClass *class;
 AVCodecContext *avctx;
@@ -91,13 +88,4 @@ typedef struct UtvideoContext {
 size_t control_stream_size[4][256];
 } UtvideoContext;
 
-typedef struct HuffEntry {
-uint16_t sym;
-uint8_t  len;
-uint32_t code;
-} HuffEntry;
-
-/* Compare huffman tree nodes */
-int ff_ut_huff_cmp_len(const void *a, const void *b);
-
 #endif /* AVCODEC_UTVIDEO_H */
diff --git a/libavcodec/utvideoenc.c b/libavcodec/utvideoenc.c
index 05a9614036..5c87eb50ac 100644
--- a/libavcodec/utvideoenc.c
+++ b/libavcodec/utvideoenc.c
@@ -37,6 +37,25 @@
 #include "utvideo.h"
 #include "huffman.h"
 
+typedef struct HuffEntry {
+uint16_t sym;
+uint8_t  len;
+uint32_t code;
+} HuffEntry;
+
+#if FF_API_PRIVATE_OPT
+static const int ut_pred_order[5] = {
+PRED_LEFT, PRED_MEDIAN, PRED_MEDIAN, PRED_NONE, PRED_GRADIENT
+};
+#endif
+
+/* Compare huffman tree nodes */
+static int ut_huff_cmp_len(const void *a, const void *b)
+{
+const HuffEntry *aa = a, *bb = b;
+return (aa->len - bb->len)*256 + aa->sym - bb->sym;
+}
+
 /* Compare huffentry symbols */
 static int huff_cmp_sym(const void *a, const void *b)
 {
@@ -139,7 +158,7 @@ FF_DISABLE_DEPRECATION_WARNINGS
 
 /* Convert from libavcodec prediction type to Ut Video's */
 if (avctx->prediction_method)
-c->frame_pred = ff_ut_pred_order[avctx->prediction_method];
+c->frame_pred = ut_pred_order[avctx->prediction_method];
 FF_ENABLE_DEPRECATION_WARNINGS
 #endif
 
@@ -340,7 +359,7 @@ static void calculate_codes(HuffEntry *he)
 int last, i;
 uint32_t code;
 
-qsort(he, 256, sizeof(*he), ff_ut_huff_cmp_len);
+qsort(he, 256, sizeof(*he), ut_huff_cmp_len);
 
 last = 255;
 while (he[last].len == 255 && last)


[FFmpeg-cvslog] avcodec/fraps: Use cached bitstream reader

2020-09-26 Thread Andreas Rheinhardt
ffmpeg | branch: master | Andreas Rheinhardt  | 
Tue Sep 22 10:12:15 2020 +0200| [a162e78cd5f6cf3d8fc30169fc7df482905df01b] | 
committer: Andreas Rheinhardt

avcodec/fraps: Use cached bitstream reader

This proved beneficial for performance: For the sample [1] the number
of decicycles in one decode call decreased from 155851561 to 108158037
for Clang 10 and from 168270467 to 128847479 for GCC 9.3. For x86-32
compiled with GCC 9.3 and run on an x64 Haswell the number increased
from 158405517 to 202215769, so that the cached bitstream reader is only
enabled if HAVE_FAST_64BIT is set. These values are the average of 10
runs each looping five times over the input.

[1]: 
samples.ffmpeg.org/ffmpeg-bugs/trac/ticket2593/fraps_flv1_decoding_errors.avi

Reviewed-by: Paul B Mahol 
Signed-off-by: Andreas Rheinhardt 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=a162e78cd5f6cf3d8fc30169fc7df482905df01b
---

 libavcodec/fraps.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/libavcodec/fraps.c b/libavcodec/fraps.c
index 00fd63ffec..8d01b44f11 100644
--- a/libavcodec/fraps.c
+++ b/libavcodec/fraps.c
@@ -31,6 +31,9 @@
  * Version 2 files support by Konstantin Shishkov
  */
 
+#include "config.h"
+
+#define CACHED_BITSTREAM_READER HAVE_FAST_64BIT
 #define UNCHECKED_BITSTREAM_READER 1
 #include "avcodec.h"
 #include "get_bits.h"

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

To unsubscribe, visit link above, or email
ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-cvslog] avcodec/utvideodec: Remove code duplication when creating Huffman tables

2020-09-26 Thread Andreas Rheinhardt
ffmpeg | branch: master | Andreas Rheinhardt  | 
Thu Sep 24 16:35:23 2020 +0200| [9c8b85f5fa5f465cfc0a88fbcbea0f4a436ece38] | 
committer: Andreas Rheinhardt

avcodec/utvideodec: Remove code duplication when creating Huffman tables

Reviewed-by: Paul B Mahol 
Signed-off-by: Andreas Rheinhardt 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=9c8b85f5fa5f465cfc0a88fbcbea0f4a436ece38
---

 libavcodec/utvideodec.c | 55 ++---
 1 file changed, 6 insertions(+), 49 deletions(-)

diff --git a/libavcodec/utvideodec.c b/libavcodec/utvideodec.c
index b3c4c3519b..f014e90606 100644
--- a/libavcodec/utvideodec.c
+++ b/libavcodec/utvideodec.c
@@ -40,7 +40,7 @@
 #include "thread.h"
 #include "utvideo.h"
 
-static int build_huff10(const uint8_t *src, VLC *vlc, int *fsym)
+static int build_huff(const uint8_t *src, VLC *vlc, int *fsym, unsigned 
nb_elems)
 {
 int i;
 HuffEntry he[1024];
@@ -51,18 +51,18 @@ static int build_huff10(const uint8_t *src, VLC *vlc, int 
*fsym)
 uint32_t code;
 
 *fsym = -1;
-for (i = 0; i < 1024; i++) {
+for (i = 0; i < nb_elems; i++) {
 he[i].sym = i;
 he[i].len = *src++;
 }
-qsort(he, 1024, sizeof(*he), ff_ut10_huff_cmp_len);
+qsort(he, nb_elems, sizeof(*he), ff_ut10_huff_cmp_len);
 
 if (!he[0].len) {
 *fsym = he[0].sym;
 return 0;
 }
 
-last = 1023;
+last = nb_elems - 1;
 while (he[last].len == 255 && last)
 last--;
 
@@ -84,49 +84,6 @@ static int build_huff10(const uint8_t *src, VLC *vlc, int 
*fsym)
   syms,  sizeof(*syms),  sizeof(*syms), 0);
 }
 
-static int build_huff(const uint8_t *src, VLC *vlc, int *fsym)
-{
-int i;
-HuffEntry he[256];
-int last;
-uint32_t codes[256];
-uint8_t bits[256];
-uint8_t syms[256];
-uint32_t code;
-
-*fsym = -1;
-for (i = 0; i < 256; i++) {
-he[i].sym = i;
-he[i].len = *src++;
-}
-qsort(he, 256, sizeof(*he), ff_ut_huff_cmp_len);
-
-if (!he[0].len) {
-*fsym = he[0].sym;
-return 0;
-}
-
-last = 255;
-while (he[last].len == 255 && last)
-last--;
-
-if (he[last].len > 32)
-return -1;
-
-code = 0;
-for (i = last; i >= 0; i--) {
-codes[i] = code >> (32 - he[i].len);
-bits[i]  = he[i].len;
-syms[i]  = he[i].sym;
-code += 0x8000u >> (he[i].len - 1);
-}
-
-return ff_init_vlc_sparse(vlc, VLC_BITS, last + 1,
-  bits,  sizeof(*bits),  sizeof(*bits),
-  codes, sizeof(*codes), sizeof(*codes),
-  syms,  sizeof(*syms),  sizeof(*syms), 0);
-}
-
 static int decode_plane10(UtvideoContext *c, int plane_no,
   uint16_t *dst, ptrdiff_t stride,
   int width, int height,
@@ -139,7 +96,7 @@ static int decode_plane10(UtvideoContext *c, int plane_no,
 GetBitContext gb;
 int prev, fsym;
 
-if ((ret = build_huff10(huff, &vlc, &fsym)) < 0) {
+if ((ret = build_huff(huff, &vlc, &fsym, 1024)) < 0) {
 av_log(c->avctx, AV_LOG_ERROR, "Cannot build Huffman codes\n");
 return ret;
 }
@@ -299,7 +256,7 @@ static int decode_plane(UtvideoContext *c, int plane_no,
 return 0;
 }
 
-if (build_huff(src, &vlc, &fsym)) {
+if (build_huff(src, &vlc, &fsym, 256)) {
 av_log(c->avctx, AV_LOG_ERROR, "Cannot build Huffman codes\n");
 return AVERROR_INVALIDDATA;
 }

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

To unsubscribe, visit link above, or email
ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-cvslog] avcodec/utvideo: Remove unused array

2020-09-26 Thread Andreas Rheinhardt
ffmpeg | branch: master | Andreas Rheinhardt  | 
Thu Sep 24 18:30:54 2020 +0200| [5f5f0b06cf1f4aed336467b826962d7f85b81a1e] | 
committer: Andreas Rheinhardt

avcodec/utvideo: Remove unused array

Unused since 3594788b713e76449eda0bc9d64b38258c86a594.

Reviewed-by: Paul B Mahol 
Signed-off-by: Andreas Rheinhardt 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=5f5f0b06cf1f4aed336467b826962d7f85b81a1e
---

 libavcodec/utvideo.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/libavcodec/utvideo.c b/libavcodec/utvideo.c
index b14e56e0d8..0cf0cbcd8b 100644
--- a/libavcodec/utvideo.c
+++ b/libavcodec/utvideo.c
@@ -32,8 +32,6 @@ const int ff_ut_pred_order[5] = {
 };
 #endif
 
-const int ff_ut_rgb_order[4]  = { 1, 2, 0, 3 }; // G, B, R, A
-
 int ff_ut_huff_cmp_len(const void *a, const void *b)
 {
 const HuffEntry *aa = a, *bb = b;

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

To unsubscribe, visit link above, or email
ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-cvslog] avcodec/magicyuv: Don't waste stack space

2020-09-26 Thread Andreas Rheinhardt
ffmpeg | branch: master | Andreas Rheinhardt  | 
Wed Sep 23 16:50:02 2020 +0200| [116b235a0b86276aea2fc9021c056744977a1527] | 
committer: Andreas Rheinhardt

avcodec/magicyuv: Don't waste stack space

Now that the HuffEntries are no longer sorted by the MagicYUV decoder,
their symbols are trivial: The symbol of the element with index i is i.
They can therefore be removed. Furthermore, despite the length of the
codes being in the range 1..32 bits, the actual value of the codes is
<= 4096 (for 12 bit content). The reason for this is that the longer
codes are on the left side of the tree, so that the higher bits of
these codes are simply zero. By using an uint16_t for the codes and
removing the symbols entry, the size of each HuffEntry is decreased from
eight to four, saving 16KB of stack space.

Reviewed-by: Paul B Mahol 
Signed-off-by: Andreas Rheinhardt 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=116b235a0b86276aea2fc9021c056744977a1527
---

 libavcodec/magicyuv.c | 14 +-
 1 file changed, 5 insertions(+), 9 deletions(-)

diff --git a/libavcodec/magicyuv.c b/libavcodec/magicyuv.c
index 7dded9b457..ea1f727e5c 100644
--- a/libavcodec/magicyuv.c
+++ b/libavcodec/magicyuv.c
@@ -46,9 +46,8 @@ typedef enum Prediction {
 } Prediction;
 
 typedef struct HuffEntry {
-uint16_t sym;
 uint8_t  len;
-uint32_t code;
+uint16_t code;
 } HuffEntry;
 
 typedef struct MagicYUVContext {
@@ -90,10 +89,9 @@ static int huff_build(HuffEntry he[], uint16_t 
codes_count[33],
 he[i].code = codes_count[he[i].len];
 codes_count[he[i].len]++;
 }
-return ff_init_vlc_sparse(vlc, FFMIN(max, 12), nb_elems,
-  &he[0].len,  sizeof(he[0]), sizeof(he[0].len),
-  &he[0].code, sizeof(he[0]), sizeof(he[0].code),
-  &he[0].sym,  sizeof(he[0]), sizeof(he[0].sym),  
0);
+return init_vlc(vlc, FFMIN(max, 12), nb_elems,
+&he[0].len,  sizeof(he[0]), sizeof(he[0].len),
+&he[0].code, sizeof(he[0]), sizeof(he[0].code), 0);
 }
 
 static void magicyuv_median_pred16(uint16_t *dst, const uint16_t *src1,
@@ -408,10 +406,8 @@ static int build_huffman(AVCodecContext *avctx, const 
uint8_t *table,
 }
 
 length_count[x] += l;
-for (; j < k; j++) {
-he[j].sym = j;
+for (; j < k; j++)
 he[j].len = x;
-}
 
 if (j == max) {
 j = 0;

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

To unsubscribe, visit link above, or email
ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-cvslog] avcodec/utvideodec/enc: Fix edge case of creating Huffman table

2020-09-26 Thread Andreas Rheinhardt
ffmpeg | branch: master | Andreas Rheinhardt  | 
Thu Sep 24 16:19:03 2020 +0200| [099feb941147fbf10d1ae941b96bf94c4b4dbd1c] | 
committer: Andreas Rheinhardt

avcodec/utvideodec/enc: Fix edge case of creating Huffman table

The Ut Video format stores Huffman tables in its bitstream by coding
the length of a given symbol; it does not code the actual code directly,
instead this is to be inferred by the rule that a symbol is to the left
of every shorter symbol in the Huffman tree and that for symbols of the
same length the symbol is descending from left to right. With one
exception, this is also what our de- and encoder did.

The exception only matters when there are codes of length 32, because
in this case the first symbol of this length did not get the code 0,
but 1; this is tantamount to pretending that there is a (nonexistent)
leaf of length 32. This is simply false. The reference software agrees
with this [1].

[1]: 
https://github.com/umezawatakeshi/utvideo/blob/2700a471a78402e5c340150b38e8a793ef3676f1/utv_core/HuffmanCode.cpp#L280

Reviewed-by: Paul B Mahol 
Signed-off-by: Andreas Rheinhardt 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=099feb941147fbf10d1ae941b96bf94c4b4dbd1c
---

 libavcodec/utvideodec.c | 4 ++--
 libavcodec/utvideoenc.c | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/libavcodec/utvideodec.c b/libavcodec/utvideodec.c
index c07636d435..b3c4c3519b 100644
--- a/libavcodec/utvideodec.c
+++ b/libavcodec/utvideodec.c
@@ -70,7 +70,7 @@ static int build_huff10(const uint8_t *src, VLC *vlc, int 
*fsym)
 return -1;
 }
 
-code = 1;
+code = 0;
 for (i = last; i >= 0; i--) {
 codes[i] = code >> (32 - he[i].len);
 bits[i]  = he[i].len;
@@ -113,7 +113,7 @@ static int build_huff(const uint8_t *src, VLC *vlc, int 
*fsym)
 if (he[last].len > 32)
 return -1;
 
-code = 1;
+code = 0;
 for (i = last; i >= 0; i--) {
 codes[i] = code >> (32 - he[i].len);
 bits[i]  = he[i].len;
diff --git a/libavcodec/utvideoenc.c b/libavcodec/utvideoenc.c
index f1b9d11c96..05a9614036 100644
--- a/libavcodec/utvideoenc.c
+++ b/libavcodec/utvideoenc.c
@@ -346,7 +346,7 @@ static void calculate_codes(HuffEntry *he)
 while (he[last].len == 255 && last)
 last--;
 
-code = 1;
+code = 0;
 for (i = last; i >= 0; i--) {
 he[i].code  = code >> (32 - he[i].len);
 code   += 0x8000u >> (he[i].len - 1);

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

To unsubscribe, visit link above, or email
ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-cvslog] avcodec/magicyuv: Don't invert order unnecessarily

2020-09-26 Thread Andreas Rheinhardt
ffmpeg | branch: master | Andreas Rheinhardt  | 
Wed Sep 23 14:19:03 2020 +0200| [68b6614e389955016a77ff182f0a8bb03d41ae52] | 
committer: Andreas Rheinhardt

avcodec/magicyuv: Don't invert order unnecessarily

The MagicYUV decoder currently sets both the length and the symbol field
of an array of HuffEntries; hereby the symbol of the ith entry (0-based)
is just i. Then said array gets sorted so that entries with greater
length are at the end and entries with the same length are ordered so
that those with smaller symbols are at the end. Afterwards the newly
sorted array is traversed in reverse order. This commit instead inverts
the ordering and traverses the array in its ordinary order in order to
simplify understanding.

Reviewed-by: Paul B Mahol 
Signed-off-by: Andreas Rheinhardt 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=68b6614e389955016a77ff182f0a8bb03d41ae52
---

 libavcodec/magicyuv.c | 7 +++
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/libavcodec/magicyuv.c b/libavcodec/magicyuv.c
index 93ee739093..1b3f4cfc6b 100644
--- a/libavcodec/magicyuv.c
+++ b/libavcodec/magicyuv.c
@@ -77,24 +77,23 @@ typedef struct MagicYUVContext {
 static int huff_cmp_len(const void *a, const void *b)
 {
 const HuffEntry *aa = a, *bb = b;
-return (aa->len - bb->len) * 4096 + bb->sym - aa->sym;
+return (bb->len - aa->len) * 4096 + aa->sym - bb->sym;
 }
 
 static int huff_build(HuffEntry he[], VLC *vlc, int nb_elems)
 {
 uint32_t code;
-int i;
 
 AV_QSORT(he, nb_elems, HuffEntry, huff_cmp_len);
 
 code = 1;
-for (i = nb_elems - 1; i >= 0; i--) {
+for (unsigned i = 0; i < nb_elems; i++) {
 he[i].code = code >> (32 - he[i].len);
 code += 0x8000u >> (he[i].len - 1);
 }
 
 ff_free_vlc(vlc);
-return ff_init_vlc_sparse(vlc, FFMIN(he[nb_elems - 1].len, 12), nb_elems,
+return ff_init_vlc_sparse(vlc, FFMIN(he[0].len, 12), nb_elems,
   &he[0].len,  sizeof(he[0]), sizeof(he[0].len),
   &he[0].code, sizeof(he[0]), sizeof(he[0].code),
   &he[0].sym,  sizeof(he[0]), sizeof(he[0].sym),  
0);

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

To unsubscribe, visit link above, or email
ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-cvslog] avcodec/utvideodec: Avoid qsort when creating Huffman tables

2020-09-26 Thread Andreas Rheinhardt
ffmpeg | branch: master | Andreas Rheinhardt  | 
Thu Sep 24 18:29:39 2020 +0200| [341914495e5c2f60bc920b0c6f660e5948a47f5a] | 
committer: Andreas Rheinhardt

avcodec/utvideodec: Avoid qsort when creating Huffman tables

The Ut video format uses Huffman trees which are only implicitly coded
in the bitstream: Only the lengths of the codes are coded, the rest has
to be inferred by the decoder according to the rule that the longer
codes are to the left of shorter codes in the tree and on each level the
symbols are descending from left to right.

Because longer codes are to the left of shorter codes, one needs to know
how many non-leaf nodes there are on each level in order to know the
code of the next left-most leaf (which belongs to the highest symbol on
that level). The current code does this by sorting the entries to be
ascending according to length and (for entries with the same length)
ascending according to their symbols. This array is then traversed in
reverse order, so that the lowest level is dealt with first, so that the
number of non-leaf nodes of the next higher level is known when
processing said level.

But this can also be calculated without sorting: Simply count how many
leaf nodes there are on each level. Then one can calculate the number of
non-leaf nodes on each level iteratively from the lowest level upwards:
It is just half the number of nodes of the level below.

This improves performance: For the sample from ticket #4044 the amount
of decicycles for one call to build_huff() decreased from 1055489 to
446310 for Clang 10 and from 1080306 to 535155 for GCC 9.

Reviewed-by: Paul B Mahol 
Signed-off-by: Andreas Rheinhardt 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=341914495e5c2f60bc920b0c6f660e5948a47f5a
---

 libavcodec/utvideo.c|  6 --
 libavcodec/utvideo.h|  1 -
 libavcodec/utvideodec.c | 53 -
 3 files changed, 26 insertions(+), 34 deletions(-)

diff --git a/libavcodec/utvideo.c b/libavcodec/utvideo.c
index 5828d5ec0d..b14e56e0d8 100644
--- a/libavcodec/utvideo.c
+++ b/libavcodec/utvideo.c
@@ -39,9 +39,3 @@ int ff_ut_huff_cmp_len(const void *a, const void *b)
 const HuffEntry *aa = a, *bb = b;
 return (aa->len - bb->len)*256 + aa->sym - bb->sym;
 }
-
-int ff_ut10_huff_cmp_len(const void *a, const void *b)
-{
-const HuffEntry *aa = a, *bb = b;
-return (aa->len - bb->len)*1024 + aa->sym - bb->sym;
-}
diff --git a/libavcodec/utvideo.h b/libavcodec/utvideo.h
index cf0bb28c44..2975f287a7 100644
--- a/libavcodec/utvideo.h
+++ b/libavcodec/utvideo.h
@@ -99,6 +99,5 @@ typedef struct HuffEntry {
 
 /* Compare huffman tree nodes */
 int ff_ut_huff_cmp_len(const void *a, const void *b);
-int ff_ut10_huff_cmp_len(const void *a, const void *b);
 
 #endif /* AVCODEC_UTVIDEO_H */
diff --git a/libavcodec/utvideodec.c b/libavcodec/utvideodec.c
index f014e90606..8b47c14d98 100644
--- a/libavcodec/utvideodec.c
+++ b/libavcodec/utvideodec.c
@@ -43,45 +43,44 @@
 static int build_huff(const uint8_t *src, VLC *vlc, int *fsym, unsigned 
nb_elems)
 {
 int i;
-HuffEntry he[1024];
-int last;
 uint32_t codes[1024];
 uint8_t bits[1024];
-uint16_t syms[1024];
-uint32_t code;
+uint16_t codes_count[33] = { 0 };
 
 *fsym = -1;
 for (i = 0; i < nb_elems; i++) {
-he[i].sym = i;
-he[i].len = *src++;
-}
-qsort(he, nb_elems, sizeof(*he), ff_ut10_huff_cmp_len);
+if (src[i] == 0) {
+*fsym = i;
+return 0;
+} else if (src[i] == 255) {
+bits[i] = 0;
+} else if (src[i] <= 32) {
+bits[i] = src[i];
+} else
+return AVERROR_INVALIDDATA;
 
-if (!he[0].len) {
-*fsym = he[0].sym;
-return 0;
+codes_count[bits[i]]++;
 }
+if (codes_count[0] == nb_elems)
+return AVERROR_INVALIDDATA;
 
-last = nb_elems - 1;
-while (he[last].len == 255 && last)
-last--;
-
-if (he[last].len > 32) {
-return -1;
+for (unsigned i = 32, nb_codes = 0; i > 0; i--) {
+uint16_t curr = codes_count[i];   // # of leafs of length i
+codes_count[i] = nb_codes / 2;// # of non-leaf nodes on level i
+nb_codes = codes_count[i] + curr; // # of nodes on level i
 }
 
-code = 0;
-for (i = last; i >= 0; i--) {
-codes[i] = code >> (32 - he[i].len);
-bits[i]  = he[i].len;
-syms[i]  = he[i].sym;
-code += 0x8000u >> (he[i].len - 1);
+for (unsigned i = nb_elems; i-- > 0;) {
+if (!bits[i]) {
+codes[i] = 0;
+continue;
+}
+codes[i] = codes_count[bits[i]]++;
 }
 #define VLC_BITS 11
-return ff_init_vlc_sparse(vlc, VLC_BITS, last + 1,
-  bits,  sizeof(*bits),  sizeof(*bits),
-  codes, sizeof(*codes), sizeof(*codes),
-  syms,  sizeof(*syms),  sizeof(*syms), 0)

[FFmpeg-cvslog] avcodec/fraps: Use unchecked bitstream reader

2020-09-26 Thread Andreas Rheinhardt
ffmpeg | branch: master | Andreas Rheinhardt  | 
Tue Sep 22 08:53:34 2020 +0200| [bc6838deb99ecd649ed483ed1ce657c70830b0af] | 
committer: Andreas Rheinhardt

avcodec/fraps: Use unchecked bitstream reader

The fraps decoder already checked for overreads manually (and errored
out in this scenario), yet it still enabled implicit checks, leading to
worse performance and more code size.

This commit disables the implicit bitstream reader checks. For the
sample [1] this improves performance from 195105896 to 155851561
decicycles for Clang 10 and from 222801887 to 168270467 decicycles when
compiled with GCC 9.3. These values are the average of 10 runs each
looping ten times over the input.

[1]: 
samples.ffmpeg.org/ffmpeg-bugs/trac/ticket2593/fraps_flv1_decoding_errors.avi

Reviewed-by: Paul B Mahol 
Signed-off-by: Andreas Rheinhardt 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=bc6838deb99ecd649ed483ed1ce657c70830b0af
---

 libavcodec/fraps.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/libavcodec/fraps.c b/libavcodec/fraps.c
index 7a7673f73f..00fd63ffec 100644
--- a/libavcodec/fraps.c
+++ b/libavcodec/fraps.c
@@ -31,6 +31,7 @@
  * Version 2 files support by Konstantin Shishkov
  */
 
+#define UNCHECKED_BITSTREAM_READER 1
 #include "avcodec.h"
 #include "get_bits.h"
 #include "huffman.h"

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

To unsubscribe, visit link above, or email
ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-cvslog] avfilter/vf_histogram: add slide modes for thistogram

2020-09-26 Thread Paul B Mahol
ffmpeg | branch: master | Paul B Mahol  | Sat Sep 26 21:57:46 
2020 +0200| [85195f6ae99931212ed89ebb59ce62d2b40d397b] | committer: Paul B Mahol

avfilter/vf_histogram: add slide modes for thistogram

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=85195f6ae99931212ed89ebb59ce62d2b40d397b
---

 doc/filters.texi   | 23 +++
 libavfilter/vf_histogram.c | 42 +-
 2 files changed, 64 insertions(+), 1 deletion(-)

diff --git a/doc/filters.texi b/doc/filters.texi
index cbb16f22b2..06572218b8 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -18270,6 +18270,29 @@ Show envelope. Default is disabled.
 
 @item ecolor, ec
 Set envelope color. Default is @code{gold}.
+
+@item slide
+Set slide mode.
+
+Available values for slide is:
+@table @samp
+@item frame
+Draw new frame when right border is reached.
+
+@item replace
+Replace old columns with new ones.
+
+@item scroll
+Scroll from right to left.
+
+@item rscroll
+Scroll from left to right.
+
+@item picture
+Draw single picture.
+@end table
+
+Default is @code{replace}.
 @end table
 
 @section threshold
diff --git a/libavfilter/vf_histogram.c b/libavfilter/vf_histogram.c
index 4800c06f26..ed6892bc8b 100644
--- a/libavfilter/vf_histogram.c
+++ b/libavfilter/vf_histogram.c
@@ -34,6 +34,7 @@ typedef struct HistogramContext {
 const AVClass *class;   ///< AVClass context for log and 
options purpose
 intthistogram;
 intenvelope;
+intslide;
 unsigned   histogram[256*256];
 inthistogram_size;
 intwidth;
@@ -354,8 +355,25 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
 max_hval_log = log2(max_hval + 1);
 
 if (s->thistogram) {
+const int bpp = 1 + (s->histogram_size > 256);
 int minh = s->histogram_size - 1, maxh = 0;
 
+if (s->slide == 2) {
+s->x_pos = out->width - 1;
+for (j = 0; j < outlink->h; j++) {
+memmove(out->data[p] + j * out->linesize[p] ,
+out->data[p] + j * out->linesize[p] + bpp,
+(outlink->w - 1) * bpp);
+}
+} else if (s->slide == 3) {
+s->x_pos = 0;
+for (j = 0; j < outlink->h; j++) {
+memmove(out->data[p] + j * out->linesize[p] + bpp,
+out->data[p] + j * out->linesize[p],
+(outlink->w - 1) * bpp);
+}
+}
+
 for (int i = 0; i < s->histogram_size; i++) {
 int idx = s->histogram_size - i - 1;
 int value = s->start[p];
@@ -443,8 +461,15 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
 out->pts = in->pts;
 av_frame_free(&in);
 s->x_pos++;
-if (s->x_pos >= s->width)
+if (s->x_pos >= s->width) {
 s->x_pos = 0;
+if (s->thistogram && (s->slide == 4 || s->slide == 0)) {
+s->out = NULL;
+goto end;
+}
+} else if (s->thistogram && s->slide == 4) {
+return 0;
+}
 
 if (s->thistogram) {
 AVFrame *clone = av_frame_clone(out);
@@ -453,6 +478,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
 return AVERROR(ENOMEM);
 return ff_filter_frame(outlink, clone);
 }
+end:
 return ff_filter_frame(outlink, out);
 }
 
@@ -491,6 +517,13 @@ AVFilter ff_vf_histogram = {
 
 #if CONFIG_THISTOGRAM_FILTER
 
+static av_cold void uninit(AVFilterContext *ctx)
+{
+HistogramContext *s = ctx->priv;
+
+av_frame_free(&s->out);
+}
+
 static const AVOption thistogram_options[] = {
 { "width", "set width", OFFSET(width), AV_OPT_TYPE_INT, {.i64=0}, 0, 8192, 
FLAGS},
 { "w", "set width", OFFSET(width), AV_OPT_TYPE_INT, {.i64=0}, 0, 8192, 
FLAGS},
@@ -501,6 +534,12 @@ static const AVOption thistogram_options[] = {
 { "e","display envelope", OFFSET(envelope), AV_OPT_TYPE_BOOL, 
{.i64=0}, 0, 1, FLAGS },
 { "ecolor", "set envelope color", OFFSET(envelope_rgba), 
AV_OPT_TYPE_COLOR, {.str="gold"}, 0, 0, FLAGS },
 { "ec", "set envelope color", OFFSET(envelope_rgba), 
AV_OPT_TYPE_COLOR, {.str="gold"}, 0, 0, FLAGS },
+{ "slide", "set slide mode", OFFSET(slide), 
AV_OPT_TYPE_INT,   {.i64=1}, 0, 4, FLAGS, "slide" },
+{"frame",   "draw new frames",   OFFSET(slide), 
AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, FLAGS, "slide"},
+{"replace", "replace old columns with new",  OFFSET(slide), 
AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, FLAGS, "slide"},
+{"scroll",  "scroll from right to left", OFFSET(slide), 
AV_OPT_TYPE_CONST, {.i64=2}, 0, 0, FLAGS, "slide"},
+{"rscroll", "scroll from left to right", OFFSET(slide), 
AV_OPT_TYPE_CONST, {.i64=3}, 0, 0, FLAGS, "slide"},
+{"picture", "display graph in single 

[FFmpeg-cvslog] avcodec/v4l2_buffers: remove unused function argument

2020-09-26 Thread Andriy Gelman
ffmpeg | branch: master | Andriy Gelman  | Thu Aug 27 
23:12:51 2020 -0400| [ff5fcd0be02cc379ed5cfa3075d4d65c8c3da81f] | committer: 
Andriy Gelman

avcodec/v4l2_buffers: remove unused function argument

Signed-off-by: Andriy Gelman 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=ff5fcd0be02cc379ed5cfa3075d4d65c8c3da81f
---

 libavcodec/v4l2_buffers.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/libavcodec/v4l2_buffers.c b/libavcodec/v4l2_buffers.c
index 02f23d954b..4b2679eb38 100644
--- a/libavcodec/v4l2_buffers.c
+++ b/libavcodec/v4l2_buffers.c
@@ -274,7 +274,7 @@ static int v4l2_buf_to_bufref(V4L2Buffer *in, int plane, 
AVBufferRef **buf)
 return ret;
 }
 
-static int v4l2_bufref_to_buf(V4L2Buffer *out, int plane, const uint8_t* data, 
int size, int offset, AVBufferRef* bref)
+static int v4l2_bufref_to_buf(V4L2Buffer *out, int plane, const uint8_t* data, 
int size, int offset)
 {
 unsigned int bytesused, length;
 
@@ -386,7 +386,7 @@ static int v4l2_buffer_swframe_to_buf(const AVFrame *frame, 
V4L2Buffer *out)
 h = AV_CEIL_RSHIFT(h, desc->log2_chroma_h);
 }
 size = frame->linesize[i] * h;
-ret = v4l2_bufref_to_buf(out, 0, frame->data[i], size, offset, 
frame->buf[i]);
+ret = v4l2_bufref_to_buf(out, 0, frame->data[i], size, offset);
 if (ret)
 return ret;
 offset += size;
@@ -395,7 +395,7 @@ static int v4l2_buffer_swframe_to_buf(const AVFrame *frame, 
V4L2Buffer *out)
 }
 
 for (i = 0; i < out->num_planes; i++) {
-ret = v4l2_bufref_to_buf(out, i, frame->buf[i]->data, 
frame->buf[i]->size, 0, frame->buf[i]);
+ret = v4l2_bufref_to_buf(out, i, frame->buf[i]->data, 
frame->buf[i]->size, 0);
 if (ret)
 return ret;
 }
@@ -479,7 +479,7 @@ int ff_v4l2_buffer_avpkt_to_buf(const AVPacket *pkt, 
V4L2Buffer *out)
 {
 int ret;
 
-ret = v4l2_bufref_to_buf(out, 0, pkt->data, pkt->size, 0, pkt->buf);
+ret = v4l2_bufref_to_buf(out, 0, pkt->data, pkt->size, 0);
 if (ret)
 return ret;
 

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

To unsubscribe, visit link above, or email
ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-cvslog] avformat/argo_brp: cosmetics

2020-09-26 Thread Zane van Iperen
ffmpeg | branch: master | Zane van Iperen  | Fri Sep 25 
12:50:53 2020 +1000| [97efac3ac11a3a6f799f1e32e5eb49e50e0d5042] | committer: 
Zane van Iperen

avformat/argo_brp: cosmetics

Signed-off-by: Zane van Iperen 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=97efac3ac11a3a6f799f1e32e5eb49e50e0d5042
---

 libavformat/argo_brp.c | 18 +-
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/libavformat/argo_brp.c b/libavformat/argo_brp.c
index d3aab92af0..4041183011 100644
--- a/libavformat/argo_brp.c
+++ b/libavformat/argo_brp.c
@@ -36,8 +36,8 @@
 #define BVID_HEADER_SIZE16
 #define MASK_HEADER_SIZE12
 #define BRP_MIN_BUFFER_SIZE FFMAX3(FFMAX3(BRP_FILE_HEADER_SIZE,\
- BRP_BLOCK_HEADER_SIZE,   \
- BRP_STREAM_HEADER_SIZE), \
+  BRP_BLOCK_HEADER_SIZE,   \
+  BRP_STREAM_HEADER_SIZE), \
   BVID_HEADER_SIZE,\
   MASK_HEADER_SIZE)
 
@@ -289,14 +289,14 @@ static int argo_brp_read_header(AVFormatContext *s)
 av_log(s, AV_LOG_TRACE, "Searching %d blocks for BASF...", 
BRP_BASF_LOOKAHEAD);
 
 for (i = 0; i < BRP_BASF_LOOKAHEAD; i++) {
-if ((ret = avio_read(pb, buf, BRP_BLOCK_HEADER_SIZE)) < 0)
-return ret;
-else if (ret != BRP_BLOCK_HEADER_SIZE)
-return AVERROR(EIO);
+if ((ret = avio_read(pb, buf, BRP_BLOCK_HEADER_SIZE)) < 0)
+return ret;
+else if (ret != BRP_BLOCK_HEADER_SIZE)
+return AVERROR(EIO);
 
-blk.stream_id = AV_RL32(buf + 0);
-blk.start_ms  = AV_RL32(buf + 4);
-blk.size  = AV_RL32(buf + 8);
+blk.stream_id = AV_RL32(buf + 0);
+blk.start_ms  = AV_RL32(buf + 4);
+blk.size  = AV_RL32(buf + 8);
 
 if (blk.stream_id == brp->basf.index || blk.stream_id == -1)
 break;

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

To unsubscribe, visit link above, or email
ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-cvslog] avformat/argo_{asf,brp}: fix potential segfault in ff_argo_asf_fill_stream()

2020-09-26 Thread Zane van Iperen
ffmpeg | branch: master | Zane van Iperen  | Fri Sep 25 
23:03:46 2020 +1000| [ebfed56858d5fc57f0b4bad7e08e9e89258702ba] | committer: 
Zane van Iperen

avformat/argo_{asf,brp}: fix potential segfault in ff_argo_asf_fill_stream()

Signed-off-by: Zane van Iperen 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=ebfed56858d5fc57f0b4bad7e08e9e89258702ba
---

 libavformat/argo_asf.c | 10 +-
 libavformat/argo_asf.h |  2 +-
 libavformat/argo_brp.c |  2 +-
 3 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/libavformat/argo_asf.c b/libavformat/argo_asf.c
index de941caeac..8e2bf21c71 100644
--- a/libavformat/argo_asf.c
+++ b/libavformat/argo_asf.c
@@ -75,17 +75,17 @@ void ff_argo_asf_parse_chunk_header(ArgoASFChunkHeader 
*hdr, const uint8_t *buf)
 hdr->flags  = AV_RL32(buf + 16);
 }
 
-int ff_argo_asf_fill_stream(AVStream *st, const ArgoASFFileHeader *fhdr,
+int ff_argo_asf_fill_stream(AVFormatContext *s, AVStream *st, const 
ArgoASFFileHeader *fhdr,
 const ArgoASFChunkHeader *ckhdr)
 {
 if (ckhdr->num_samples != ASF_SAMPLE_COUNT) {
-av_log(st, AV_LOG_ERROR, "Invalid sample count. Got %u, expected %d\n",
+av_log(s, AV_LOG_ERROR, "Invalid sample count. Got %u, expected %d\n",
ckhdr->num_samples, ASF_SAMPLE_COUNT);
 return AVERROR_INVALIDDATA;
 }
 
 if ((ckhdr->flags & ASF_CF_ALWAYS1) != ASF_CF_ALWAYS1 || (ckhdr->flags & 
ASF_CF_ALWAYS0) != 0) {
-avpriv_request_sample(st, "Nonstandard flags (0x%08X)", ckhdr->flags);
+avpriv_request_sample(s, "Nonstandard flags (0x%08X)", ckhdr->flags);
 return AVERROR_PATCHWELCOME;
 }
 
@@ -116,7 +116,7 @@ int ff_argo_asf_fill_stream(AVStream *st, const 
ArgoASFFileHeader *fhdr,
 
 if (st->codecpar->bits_per_raw_sample != 16) {
 /* The header allows for these, but I've never seen any files with 
them. */
-avpriv_request_sample(st, "Non 16-bit samples");
+avpriv_request_sample(s, "Non 16-bit samples");
 return AVERROR_PATCHWELCOME;
 }
 
@@ -212,7 +212,7 @@ static int argo_asf_read_header(AVFormatContext *s)
 
 ff_argo_asf_parse_chunk_header(&asf->ckhdr, buf);
 
-return ff_argo_asf_fill_stream(st, &asf->fhdr, &asf->ckhdr);
+return ff_argo_asf_fill_stream(s, st, &asf->fhdr, &asf->ckhdr);
 }
 
 static int argo_asf_read_packet(AVFormatContext *s, AVPacket *pkt)
diff --git a/libavformat/argo_asf.h b/libavformat/argo_asf.h
index eb2669a63f..e65125fb79 100644
--- a/libavformat/argo_asf.h
+++ b/libavformat/argo_asf.h
@@ -65,7 +65,7 @@ enum {
 void ff_argo_asf_parse_file_header(ArgoASFFileHeader *hdr, const uint8_t *buf);
 int  ff_argo_asf_validate_file_header(AVFormatContext *s, const 
ArgoASFFileHeader *hdr);
 void ff_argo_asf_parse_chunk_header(ArgoASFChunkHeader *hdr, const uint8_t 
*buf);
-int  ff_argo_asf_fill_stream(AVStream *st, const ArgoASFFileHeader *fhdr,
+int  ff_argo_asf_fill_stream(AVFormatContext *s, AVStream *st, const 
ArgoASFFileHeader *fhdr,
  const ArgoASFChunkHeader *ckhdr);
 
 #endif /* AVFORMAT_ARGO_ASF_H */
diff --git a/libavformat/argo_brp.c b/libavformat/argo_brp.c
index c417818639..a60de59f64 100644
--- a/libavformat/argo_brp.c
+++ b/libavformat/argo_brp.c
@@ -289,7 +289,7 @@ static int argo_brp_read_header(AVFormatContext *s)
 
 ff_argo_asf_parse_chunk_header(&brp->basf.ckhdr, buf);
 
-if ((ret = ff_argo_asf_fill_stream(st, &hdr->extradata.basf, 
&brp->basf.ckhdr)) < 0)
+if ((ret = ff_argo_asf_fill_stream(s, st, &hdr->extradata.basf, 
&brp->basf.ckhdr)) < 0)
 return ret;
 
 /* Convert ms to samples. */

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

To unsubscribe, visit link above, or email
ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-cvslog] avformat/argo_brp: support MASK streams

2020-09-26 Thread Zane van Iperen
ffmpeg | branch: master | Zane van Iperen  | Fri Sep 25 
22:39:46 2020 +1000| [2e7752a242030edd016946289dc55eb0d617] | committer: 
Zane van Iperen

avformat/argo_brp: support MASK streams

We can't actually use them though.

Signed-off-by: Zane van Iperen 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=2e7752a242030edd016946289dc55eb0d617
---

 libavformat/argo_brp.c | 27 +--
 1 file changed, 25 insertions(+), 2 deletions(-)

diff --git a/libavformat/argo_brp.c b/libavformat/argo_brp.c
index a60de59f64..613f04aef2 100644
--- a/libavformat/argo_brp.c
+++ b/libavformat/argo_brp.c
@@ -33,13 +33,16 @@
 #define BRP_STREAM_HEADER_SIZE  20
 #define BRP_MAX_STREAMS 32 /* Soft cap, but even this is overkill. */
 #define BVID_HEADER_SIZE16
-#define BRP_MIN_BUFFER_SIZE FFMAX(FFMAX3(BRP_FILE_HEADER_SIZE,\
+#define MASK_HEADER_SIZE12
+#define BRP_MIN_BUFFER_SIZE FFMAX3(FFMAX3(BRP_FILE_HEADER_SIZE,\
  BRP_BLOCK_HEADER_SIZE,   \
  BRP_STREAM_HEADER_SIZE), \
-  BVID_HEADER_SIZE)
+  BVID_HEADER_SIZE,\
+  MASK_HEADER_SIZE)
 
 #define BRP_CODEC_ID_BVID   MKTAG('B', 'V', 'I', 'D')
 #define BRP_CODEC_ID_BASF   MKTAG('B', 'A', 'S', 'F')
+#define BRP_CODEC_ID_MASK   MKTAG('M', 'A', 'S', 'K')
 
 typedef struct ArgoBRPFileHeader {
 uint32_t magic;
@@ -60,6 +63,12 @@ typedef struct ArgoBVIDHeader {
 uint32_t depth;
 } ArgoBVIDHeader;
 
+typedef struct ArgoMASKHeader {
+uint32_t num_frames;
+uint32_t width;
+uint32_t height;
+} ArgoMASKHeader;
+
 typedef struct ArgoBRPStreamHeader {
 uint32_t codec_id;
 uint32_t id;
@@ -72,6 +81,8 @@ typedef struct ArgoBRPStreamHeader {
 ArgoBVIDHeaderbvid;
 /* If codec_id == BRP_CODEC_ID_BASF */
 ArgoASFFileHeader basf;
+/* If codec_id == BRP_CODEC_ID_MASK */
+ArgoMASKHeadermask;
 } extradata;
 } ArgoBRPStreamHeader;
 
@@ -106,6 +117,9 @@ static int read_extradata(AVFormatContext *s, const 
ArgoBRPStreamHeader *hdr,
 } else if (hdr->codec_id == BRP_CODEC_ID_BASF) {
 name = "BASF";
 size = ASF_FILE_HEADER_SIZE;
+} else if (hdr->codec_id == BRP_CODEC_ID_MASK) {
+name = "MASK";
+size = MASK_HEADER_SIZE;
 } else {
 avpriv_request_sample(s, "BRP codec id 0x%x", hdr->codec_id);
 
@@ -240,7 +254,16 @@ static int argo_brp_read_header(AVFormatContext *s)
 
 if ((ret = ff_argo_asf_validate_file_header(s, 
&hdr->extradata.basf)) < 0)
 return ret;
+} else if (hdr->codec_id == BRP_CODEC_ID_MASK) {
+ArgoMASKHeader *mask = &hdr->extradata.mask;
+
+st->codecpar->codec_type = AVMEDIA_TYPE_DATA;
+
+mask->num_frames = AV_RL32(buf + 0);
+mask->width  = AV_RL32(buf + 4);
+mask->height = AV_RL32(buf + 8);
 
+st->nb_frames= mask->num_frames;
 } else {
 av_assert0(0); /* Caught above, should never happen. */
 }

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

To unsubscribe, visit link above, or email
ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-cvslog] avformat/argo_brp: handle the case where the BASF block isn't the first

2020-09-26 Thread Zane van Iperen
ffmpeg | branch: master | Zane van Iperen  | Fri Sep 25 
12:49:58 2020 +1000| [da5ab5a0b638d214f7efcf4b22bae8a87d9e565b] | committer: 
Zane van Iperen

avformat/argo_brp: handle the case where the BASF block isn't the first

Signed-off-by: Zane van Iperen 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=da5ab5a0b638d214f7efcf4b22bae8a87d9e565b
---

 libavformat/argo_brp.c | 28 
 1 file changed, 20 insertions(+), 8 deletions(-)

diff --git a/libavformat/argo_brp.c b/libavformat/argo_brp.c
index 613f04aef2..d3aab92af0 100644
--- a/libavformat/argo_brp.c
+++ b/libavformat/argo_brp.c
@@ -32,6 +32,7 @@
 #define BRP_BLOCK_HEADER_SIZE   12
 #define BRP_STREAM_HEADER_SIZE  20
 #define BRP_MAX_STREAMS 32 /* Soft cap, but even this is overkill. */
+#define BRP_BASF_LOOKAHEAD  10 /* How many blocks to search for the first 
BASF one. */
 #define BVID_HEADER_SIZE16
 #define MASK_HEADER_SIZE12
 #define BRP_MIN_BUFFER_SIZE FFMAX3(FFMAX3(BRP_FILE_HEADER_SIZE,\
@@ -269,16 +270,13 @@ static int argo_brp_read_header(AVFormatContext *s)
 }
 }
 
-/*
- * This is nasty. BASF streams have their chunk header in each block,
- * so the first one needs to be read to get the stream info. It should
- * always be the first one.
- */
+/* Try to find the first BASF chunk. */
 if (brp->basf.index >= 0) {
 AVStream *st = s->streams[brp->basf.index];
 ArgoBRPStreamHeader *hdr = brp->streams + brp->basf.index;
 ArgoBRPBlockHeader blk;
 int64_t offset;
+int i;
 
 av_assert0(st->codecpar->codec_id == AV_CODEC_ID_ADPCM_ARGO);
 av_assert0(brp->streams[brp->basf.index].extradata_size == 
ASF_FILE_HEADER_SIZE);
@@ -288,6 +286,9 @@ static int argo_brp_read_header(AVFormatContext *s)
 
 offset = ret;
 
+av_log(s, AV_LOG_TRACE, "Searching %d blocks for BASF...", 
BRP_BASF_LOOKAHEAD);
+
+for (i = 0; i < BRP_BASF_LOOKAHEAD; i++) {
 if ((ret = avio_read(pb, buf, BRP_BLOCK_HEADER_SIZE)) < 0)
 return ret;
 else if (ret != BRP_BLOCK_HEADER_SIZE)
@@ -297,11 +298,21 @@ static int argo_brp_read_header(AVFormatContext *s)
 blk.start_ms  = AV_RL32(buf + 4);
 blk.size  = AV_RL32(buf + 8);
 
-if (blk.stream_id != brp->basf.index) {
-avpriv_request_sample(s, "first block not BASF");
-return AVERROR_PATCHWELCOME;
+if (blk.stream_id == brp->basf.index || blk.stream_id == -1)
+break;
+
+if ((ret = avio_skip(pb, blk.size)) < 0)
+return ret;
+}
+
+if (i == BRP_BASF_LOOKAHEAD || blk.stream_id == -1) {
+/* Don't error here, as there may still be a valid video stream. */
+av_log(s, AV_LOG_TRACE, "not found\n");
+goto done;
 }
 
+av_log(s, AV_LOG_TRACE, "found at index %d\n", i);
+
 if (blk.size < ASF_CHUNK_HEADER_SIZE)
 return AVERROR_INVALIDDATA;
 
@@ -319,6 +330,7 @@ static int argo_brp_read_header(AVFormatContext *s)
 st->start_time = av_rescale_rnd(blk.start_ms, 
st->codecpar->sample_rate, 1000, AV_ROUND_UP);
 st->duration   = av_rescale_rnd(hdr->duration_ms, 
st->codecpar->sample_rate, 1000, AV_ROUND_UP);
 
+done:
 if ((ret = avio_seek(s->pb, offset, SEEK_SET)) < 0)
 return ret;
 }

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

To unsubscribe, visit link above, or email
ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-cvslog] avformat/argo_brp: allow v1.1 ASF streams to have a non-22050 sample rate in certain circumstances

2020-09-26 Thread Zane van Iperen
ffmpeg | branch: master | Zane van Iperen  | Fri Sep 25 
22:25:42 2020 +1000| [3ffb15a105f88544b6b93bb32c9ac9f62b90f456] | committer: 
Zane van Iperen

avformat/argo_brp: allow v1.1 ASF streams to have a non-22050 sample rate in 
certain circumstances

It seems that in files where the BASF block isn't first, v1.1 ASF streams are
allowed to be non-22050. Either this format is really inconsistent, or
FX Fighter and Croc just ignored the sample rate field, requiring the v1.1
restriction in the first place.

This bumps the version to 1.2 in these streams so they're not "corrected".

Found in Alien Odyssey games files in:
./GRAPHICS/COMMBUNK/{{COMADD1,COMM2_{1,2,3E},COMM3_{2,3,4,5,6}},FADE{1,2}}.BRP

Signed-off-by: Zane van Iperen 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=3ffb15a105f88544b6b93bb32c9ac9f62b90f456
---

 libavformat/argo_brp.c | 14 ++
 1 file changed, 14 insertions(+)

diff --git a/libavformat/argo_brp.c b/libavformat/argo_brp.c
index 4041183011..af64a0d6dc 100644
--- a/libavformat/argo_brp.c
+++ b/libavformat/argo_brp.c
@@ -323,6 +323,20 @@ static int argo_brp_read_header(AVFormatContext *s)
 
 ff_argo_asf_parse_chunk_header(&brp->basf.ckhdr, buf);
 
+/*
+ * Special Case Hack. It seems that in files where the BASF block 
isn't first,
+ * v1.1 streams are allowed to be non-22050...
+ * Bump the version to 1.2 so ff_argo_asf_fill_stream() doesn't 
"correct" it.
+ *
+ * Found in Alien Odyssey games files in:
+ * 
./GRAPHICS/COMMBUNK/{{COMADD1,COMM2_{1,2,3E},COMM3_{2,3,4,5,6}},FADE{1,2}}.BRP
+ *
+ * Either this format really inconsistent, or FX Fighter and Croc just 
ignored the
+ * sample rate field...
+ */
+if (i != 0 && hdr->extradata.basf.version_major == 1 && 
hdr->extradata.basf.version_minor == 1)
+hdr->extradata.basf.version_minor = 2;
+
 if ((ret = ff_argo_asf_fill_stream(s, st, &hdr->extradata.basf, 
&brp->basf.ckhdr)) < 0)
 return ret;
 

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

To unsubscribe, visit link above, or email
ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-cvslog] avformat/argo_brp: use header frame counts

2020-09-26 Thread Zane van Iperen
ffmpeg | branch: master | Zane van Iperen  | Sat Sep 26 
12:21:45 2020 +1000| [ce30c3d5b9601ccb7d94ce0cc7ffe947264509cb] | committer: 
Zane van Iperen

avformat/argo_brp: use header frame counts

Signed-off-by: Zane van Iperen 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=ce30c3d5b9601ccb7d94ce0cc7ffe947264509cb
---

 libavformat/argo_brp.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/libavformat/argo_brp.c b/libavformat/argo_brp.c
index af64a0d6dc..76b4da2e66 100644
--- a/libavformat/argo_brp.c
+++ b/libavformat/argo_brp.c
@@ -237,6 +237,8 @@ static int argo_brp_read_header(AVFormatContext *s)
 avpriv_request_sample(s, "depth == %u", bvid->depth);
 return AVERROR_PATCHWELCOME;
 }
+
+st->nb_frames = bvid->num_frames;
 } else if (hdr->codec_id == BRP_CODEC_ID_BASF) {
 /*
  * It would make the demuxer significantly more complicated
@@ -255,6 +257,8 @@ static int argo_brp_read_header(AVFormatContext *s)
 
 if ((ret = ff_argo_asf_validate_file_header(s, 
&hdr->extradata.basf)) < 0)
 return ret;
+
+st->nb_frames = hdr->extradata.basf.num_chunks;
 } else if (hdr->codec_id == BRP_CODEC_ID_MASK) {
 ArgoMASKHeader *mask = &hdr->extradata.mask;
 

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

To unsubscribe, visit link above, or email
ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".