[FFmpeg-devel] [PATCH] Revised ff_v210_planar_unpack AVX2

2019-03-06 Thread Michael Stoner
---
 libavcodec/v210dec.c   | 10 +-
 libavcodec/x86/v210-init.c |  8 +
 libavcodec/x86/v210.asm| 63 --
 3 files changed, 64 insertions(+), 17 deletions(-)

diff --git a/libavcodec/v210dec.c b/libavcodec/v210dec.c
index ddc5dbe8be..26954c0df3 100644
--- a/libavcodec/v210dec.c
+++ b/libavcodec/v210dec.c
@@ -119,7 +119,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, 
int *got_frame,
 const uint32_t *src = (const uint32_t*)psrc;
 uint32_t val;
 
-w = (avctx->width / 6) * 6;
+w = (avctx->width / 12) * 12;
 s->unpack_frame(src, y, u, v, w);
 
 y += w;
@@ -127,6 +127,14 @@ static int decode_frame(AVCodecContext *avctx, void *data, 
int *got_frame,
 v += w >> 1;
 src += (w << 1) / 3;
 
+if (w < avctx->width - 5) {
+   READ_PIXELS(u, y, v);
+   READ_PIXELS(y, u, y);
+   READ_PIXELS(v, y, u);
+   READ_PIXELS(y, v, y);
+w += 6;
+}
+
 if (w < avctx->width - 1) {
 READ_PIXELS(u, y, v);
 
diff --git a/libavcodec/x86/v210-init.c b/libavcodec/x86/v210-init.c
index d64dbca1a8..cb9a6cbd6a 100644
--- a/libavcodec/x86/v210-init.c
+++ b/libavcodec/x86/v210-init.c
@@ -21,9 +21,11 @@
 
 extern void ff_v210_planar_unpack_unaligned_ssse3(const uint32_t *src, 
uint16_t *y, uint16_t *u, uint16_t *v, int width);
 extern void ff_v210_planar_unpack_unaligned_avx(const uint32_t *src, uint16_t 
*y, uint16_t *u, uint16_t *v, int width);
+extern void ff_v210_planar_unpack_unaligned_avx2(const uint32_t *src, uint16_t 
*y, uint16_t *u, uint16_t *v, int width);
 
 extern void ff_v210_planar_unpack_aligned_ssse3(const uint32_t *src, uint16_t 
*y, uint16_t *u, uint16_t *v, int width);
 extern void ff_v210_planar_unpack_aligned_avx(const uint32_t *src, uint16_t 
*y, uint16_t *u, uint16_t *v, int width);
+extern void ff_v210_planar_unpack_aligned_avx2(const uint32_t *src, uint16_t 
*y, uint16_t *u, uint16_t *v, int width);
 
 av_cold void ff_v210_x86_init(V210DecContext *s)
 {
@@ -36,6 +38,9 @@ av_cold void ff_v210_x86_init(V210DecContext *s)
 
 if (HAVE_AVX_EXTERNAL && cpu_flags & AV_CPU_FLAG_AVX)
 s->unpack_frame = ff_v210_planar_unpack_aligned_avx;
+
+if (HAVE_AVX2_EXTERNAL && cpu_flags & AV_CPU_FLAG_AVX2)
+s->unpack_frame = ff_v210_planar_unpack_aligned_avx2;
 }
 else {
 if (cpu_flags & AV_CPU_FLAG_SSSE3)
@@ -43,6 +48,9 @@ av_cold void ff_v210_x86_init(V210DecContext *s)
 
 if (HAVE_AVX_EXTERNAL && cpu_flags & AV_CPU_FLAG_AVX)
 s->unpack_frame = ff_v210_planar_unpack_unaligned_avx;
+
+if (HAVE_AVX2_EXTERNAL && cpu_flags & AV_CPU_FLAG_AVX2)
+s->unpack_frame = ff_v210_planar_unpack_unaligned_avx2;
 }
 #endif
 }
diff --git a/libavcodec/x86/v210.asm b/libavcodec/x86/v210.asm
index c24c765e5b..064185354f 100644
--- a/libavcodec/x86/v210.asm
+++ b/libavcodec/x86/v210.asm
@@ -22,9 +22,12 @@
 
 %include "libavutil/x86/x86util.asm"
 
-SECTION_RODATA
+SECTION_RODATA 32
+
+; for AVX2 version only
+v210_luma_permute: dd 0,1,2,4,5,6,7,7  ; 32-byte alignment required
+v210_chroma_shuf2: db 0,1,2,3,4,5,8,9,10,11,12,13,-1,-1,-1,-1
 
-v210_mask: times 4 dd 0x3ff
 v210_mult: dw 64,4,64,4,64,4,64,4
 v210_luma_shuf: db 8,9,0,1,2,3,12,13,4,5,6,7,-1,-1,-1,-1
 v210_chroma_shuf: db 0,1,8,9,6,7,-1,-1,2,3,4,5,12,13,-1,-1
@@ -34,40 +37,58 @@ SECTION .text
 %macro v210_planar_unpack 1
 
 ; v210_planar_unpack(const uint32_t *src, uint16_t *y, uint16_t *u, uint16_t 
*v, int width)
-cglobal v210_planar_unpack_%1, 5, 5, 7
+cglobal v210_planar_unpack_%1, 5, 5, 8
 movsxdifnidn r4, r4d
 lear1, [r1+2*r4]
 addr2, r4
 addr3, r4
 negr4
 
-mova   m3, [v210_mult]
-mova   m4, [v210_mask]
-mova   m5, [v210_luma_shuf]
-mova   m6, [v210_chroma_shuf]
+VBROADCASTI128   m3, [v210_mult]
+VBROADCASTI128   m4, [v210_luma_shuf]
+VBROADCASTI128   m5, [v210_chroma_shuf]
+
+%if cpuflag(avx2)
+mova m6, [v210_luma_permute]
+VBROADCASTI128   m7, [v210_chroma_shuf2]
+%endif
+
 .loop:
 %ifidn %1, unaligned
-movu   m0, [r0]
+movu   m0, [r0]; yB v5 yA  u5 y9 v4  y8 u4 y7  v3 y6 u3  y5 v2 y4  u2 
y3 v1  y2 u1 y1  v0 y0 u0
 %else
 mova   m0, [r0]
 %endif
 
 pmullw m1, m0, m3
-psrld  m0, 10
-psrlw  m1, 6  ; u0 v0 y1 y2 v1 u2 y4 y5
-pand   m0, m4 ; y0 __ u1 __ y3 __ v2 __
+pslld  m0, 12
+psrlw  m1, 6   ; yB yA u5 v4 y8 y7 v3 u3 y5 y4 u2 v1 
y2 y1 v0 u0
+psrld  m0, 22  ; 00 v5 00 y9 00 u4 00 y6 00 v2 00 y3 
00 u1 00 y0
+
+shufps m2, m1, m0, 0x8d; 00 y9 00 y6 yB yA y8 y7 00 y3 00 y0 
y5 y4 y2 y1
+pshufb m2, m4  ; 00 00 yB yA y9 y8 y7 y6 00 00 y5 y4 
y3 y2 y1 y0
+
+%if cpuflag(avx2)
+vpermd m2, m6, m2  ; 00 00 00 00 yB yA y9 y8 y7 

Re: [FFmpeg-devel] [PATCH] Added ff_v210_planar_unpack_aligned_avx2

2019-03-06 Thread Mike Stoner
 Thanks for the feedback.  You are right, I can use VPERMQ to free up a 
register.  I can also remove the PAND mask by doing PSLLD/PSRLD.  That 
eliminates the need for an x86-64 block.
I tried the naive 'unrolled' version with no permute, and it was much slower, 
about the same as the AVX/SSSE3 code.  VPERMQ/D is a single shuffle uop on port 
5, so it turns out to be useful.
I will submit a new patch with those improvements and the VBROADCASTI128 macro. 
 I role-modeled my code from 'v210enc.asm' which also could be updated with 
VBROADCASTI128.
Note, I'm running on Windows and it looks like 'checkasm' performance 
benchmarking is only enabled on Linux.  For my tests I put a 100x loop around 
the 'unpack_frame' call and ran:
ffmpeg.exe -s:v 1920x1080 -vcodec v210  -stream_loop 200 -i 
OddaView_1920x1080.v210  -f null -y NUL
If there is a better way, let me know...
Thanks,Mike
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] avutil/mem: Mark DECLARE_ASM_ALIGNED as visibility("hidden") for __GNUC__

2019-03-06 Thread Fāng-ruì Sòng
Sorry, wrong signed-off-by line..

(isn't using my usual mail client mutt and i get very sick of the
webmail...)

On Thu, Mar 7, 2019 at 11:36 AM Fāng-ruì Sòng  wrote:

> On Wed, Mar 6, 2019 at 4:14 PM Carl Eugen Hoyos 
> wrote:
>
>> 2019-02-21 2:37 GMT+01:00, Fāng-ruì Sòng <
>> maskray-at-google@ffmpeg.org>:
>> > Sorry if this doesn't attach to the correct thread as I didn't
>> > subscribe to this list and don't know the Message-ID of the thread.
>>
>> The thread works fine here with gmail but your patch was corrupted,
>> you have to attach it.
>>
>> Carl Eugen
>>
>>
> Sorry. Here is the attached patch (git format-patch -1 --stdout).
>


-- 
宋方睿
From 63d1c46c9796ca4a804cc89573c8f4613716b50d Mon Sep 17 00:00:00 2001
From: Fangrui Song 
Date: Wed, 20 Feb 2019 16:25:46 +0800
Subject: [PATCH] avutil/mem: Mark DECLARE_ASM_ALIGNED as visibility("hidden") for __GNUC__

Inline asm code assumes these DECLARE_ASM_ALIGNED declared global constants are non-preemptive, e.g.

libavcodec/x86/cabac.h
"lea"MANGLE(ff_h264_cabac_tables)", %0  \n\t"

On ELF platforms, when -Wl,-Bsymbolic
-Wl,--version-script,libavcodec/libavcodec.ver are removed from the
linker command line, the symbol will be considered preemptive and fail
to link to a DSO:

ld.lld: error: relocation R_X86_64_PC32 cannot be used against symbol ff_h264_cabac_tables; recompile with -fPIC

It is better to express the intention explicitly and mark such global
constants hidden. It also improves portability as no linker magic is
required.

DECLARE_ASM_CONST uses the "static" specifier to indicate internal
linkage. The visibility annotation is unnecessary.

Signed-off-by: Fangrui Song 
---
 libavutil/mem.h | 8 +++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/libavutil/mem.h b/libavutil/mem.h
index 5fb1a02..9afeed0 100644
--- a/libavutil/mem.h
+++ b/libavutil/mem.h
@@ -100,6 +100,12 @@
  * @param v Name of the variable
  */
 
+#if defined(__GNUC__) && !(defined(_WIN32) || defined(__CYGWIN__))
+#define DECLARE_HIDDEN __attribute__ ((visibility ("hidden")))
+#else
+#define DECLARE_HIDDEN
+#endif
+
 #if defined(__INTEL_COMPILER) && __INTEL_COMPILER < 1110 || defined(__SUNPRO_C)
 #define DECLARE_ALIGNED(n,t,v)  t __attribute__ ((aligned (n))) v
 #define DECLARE_ASM_ALIGNED(n,t,v)  t __attribute__ ((aligned (n))) v
@@ -110,7 +116,7 @@
 #define DECLARE_ASM_CONST(n,t,v)static const t av_used __attribute__ ((aligned (FFMIN(n, 16 v
 #elif defined(__GNUC__) || defined(__clang__)
 #define DECLARE_ALIGNED(n,t,v)  t __attribute__ ((aligned (n))) v
-#define DECLARE_ASM_ALIGNED(n,t,v)  t av_used __attribute__ ((aligned (n))) v
+#define DECLARE_ASM_ALIGNED(n,t,v)  t av_used __attribute__ ((aligned (n))) DECLARE_HIDDEN v
 #define DECLARE_ASM_CONST(n,t,v)static const t av_used __attribute__ ((aligned (n))) v
 #elif defined(_MSC_VER)
 #define DECLARE_ALIGNED(n,t,v)  __declspec(align(n)) t v
-- 
2.20.1

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


Re: [FFmpeg-devel] [PATCH] avutil/mem: Mark DECLARE_ASM_ALIGNED as visibility("hidden") for __GNUC__

2019-03-06 Thread Fāng-ruì Sòng
On Wed, Mar 6, 2019 at 4:14 PM Carl Eugen Hoyos  wrote:

> 2019-02-21 2:37 GMT+01:00, Fāng-ruì Sòng  >:
> > Sorry if this doesn't attach to the correct thread as I didn't
> > subscribe to this list and don't know the Message-ID of the thread.
>
> The thread works fine here with gmail but your patch was corrupted,
> you have to attach it.
>
> Carl Eugen
>
>
Sorry. Here is the attached patch (git format-patch -1 --stdout).
From 63d1c46c9796ca4a804cc89573c8f4613716b50d Mon Sep 17 00:00:00 2001
From: Fangrui Song 
Date: Wed, 20 Feb 2019 16:25:46 +0800
Subject: [PATCH] avutil/mem: Mark DECLARE_ASM_ALIGNED as visibility("hidden")
 for __GNUC__

Inline asm code assumes these DECLARE_ASM_ALIGNED declared global constants are non-preemptive, e.g.

libavcodec/x86/cabac.h
"lea"MANGLE(ff_h264_cabac_tables)", %0  \n\t"

On ELF platforms, when -Wl,-Bsymbolic
-Wl,--version-script,libavcodec/libavcodec.ver are removed from the
linker command line, the symbol will be considered preemptive and fail
to link to a DSO:

ld.lld: error: relocation R_X86_64_PC32 cannot be used against symbol ff_h264_cabac_tables; recompile with -fPIC

It is better to express the intention explicitly and mark such global
constants hidden. It also improves portability as no linker magic is
required.

DECLARE_ASM_CONST uses the "static" specifier to indicate internal
linkage. The visibility annotation is unnecessary.

Signed-off-by: Fangrui Song 
---
 libavutil/mem.h | 8 +++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/libavutil/mem.h b/libavutil/mem.h
index 5fb1a02..9afeed0 100644
--- a/libavutil/mem.h
+++ b/libavutil/mem.h
@@ -100,6 +100,12 @@
  * @param v Name of the variable
  */
 
+#if defined(__GNUC__) && !(defined(_WIN32) || defined(__CYGWIN__))
+#define DECLARE_HIDDEN __attribute__ ((visibility ("hidden")))
+#else
+#define DECLARE_HIDDEN
+#endif
+
 #if defined(__INTEL_COMPILER) && __INTEL_COMPILER < 1110 || defined(__SUNPRO_C)
 #define DECLARE_ALIGNED(n,t,v)  t __attribute__ ((aligned (n))) v
 #define DECLARE_ASM_ALIGNED(n,t,v)  t __attribute__ ((aligned (n))) v
@@ -110,7 +116,7 @@
 #define DECLARE_ASM_CONST(n,t,v)static const t av_used __attribute__ ((aligned (FFMIN(n, 16 v
 #elif defined(__GNUC__) || defined(__clang__)
 #define DECLARE_ALIGNED(n,t,v)  t __attribute__ ((aligned (n))) v
-#define DECLARE_ASM_ALIGNED(n,t,v)  t av_used __attribute__ ((aligned (n))) v
+#define DECLARE_ASM_ALIGNED(n,t,v)  t av_used __attribute__ ((aligned (n))) DECLARE_HIDDEN v
 #define DECLARE_ASM_CONST(n,t,v)static const t av_used __attribute__ ((aligned (n))) v
 #elif defined(_MSC_VER)
 #define DECLARE_ALIGNED(n,t,v)  __declspec(align(n)) t v
-- 
2.20.1

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


Re: [FFmpeg-devel] [PATCH 4/5] vaapi_encode: Add ROI support

2019-03-06 Thread Guo, Yejun


> -Original Message-
> From: ffmpeg-devel [mailto:ffmpeg-devel-boun...@ffmpeg.org] On Behalf
> Of Mark Thompson
> Sent: Tuesday, March 05, 2019 8:26 AM
> To: ffmpeg-devel@ffmpeg.org
> Subject: Re: [FFmpeg-devel] [PATCH 4/5] vaapi_encode: Add ROI support
> 
> On 28/02/2019 06:33, Guo, Yejun wrote:>> -Original Message-
> >> From: ffmpeg-devel [mailto:ffmpeg-devel-boun...@ffmpeg.org] On
> Behalf
> >> Of Mark Thompson
> >> Sent: Thursday, February 28, 2019 6:00 AM
> >> To: ffmpeg-devel@ffmpeg.org
> >> Subject: [FFmpeg-devel] [PATCH 4/5] vaapi_encode: Add ROI support
> >>
> >> ---
> >>  libavcodec/vaapi_encode.c   | 129
> >> 
> >>  libavcodec/vaapi_encode.h   |   9 +++
> >>  libavcodec/vaapi_encode_h264.c  |   2 +
> >>  libavcodec/vaapi_encode_h265.c  |   2 +
> >>  libavcodec/vaapi_encode_mpeg2.c |   2 +
> >>  libavcodec/vaapi_encode_vp8.c   |   2 +
> >>  libavcodec/vaapi_encode_vp9.c   |   2 +
> >>  7 files changed, 148 insertions(+)
> >
> > I tried this patch with below command, but do not see any quality change
> with my eyes.
> > I debugged in gdb and  found the ROI data are correct in function
> vaapi_encode_issue.
> >
> > I do not investigate deeper, and just want to first confirm if you see the
> quality change or not. I might did something basic wrong.
> >
> > ffmpeg_g -hwaccel vaapi -vaapi_device /dev/dri/renderD128  -s 1920x1080
> -i ../video
> > /1080P_park_joy_1920x1080_500frames.yuv   -vf format=nv12,hwupload
> -c:v h264_vaapi  -b:v 3M  -y tmp.264
> > (my trick code in vf_scale.c is called with the above command)
> >
> > I tried the similar option with libx264 and found obvious video quality
> changes.
> 
> If you are using the i965 driver then you might need
>  to make it work.  The
> iHD driver worked for me with no changes.
> 
> In CQP mode with H.264 it's straightforward to verify the output directly, too
> - any stream analyser or other tool which can show the QP on each
> macroblock will make it very obvious, since you will see exactly the offset 
> you
> set in your regions of interest.  (The reference decoder with trace enabled
> shows it as mb_qp_delta as well.)

yes, CQP mode is more straightforward. I can see the difference obviously with
my eyes when using option "-qp 50", and yes, with the analyzer tool, I can see
each MB's final qp is set as expected, but do not see the difference in 
'slice_qp_delta'
and 'mb_qp_delta' in the analyzer.

> 
> Thanks,
> 
> - Mark
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH v3] avformat/mpegts: reduce buffering during initialization

2019-03-06 Thread Andriy Gelman
From: Andriy Gelman 

Reduces buffering latency with low bitrate streams, where
8192 bytes can mean several seconds.
---
 libavformat/mpegts.c | 60 +++-
 1 file changed, 37 insertions(+), 23 deletions(-)

diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c
index b04fd7b4f4..7d03500043 100644
--- a/libavformat/mpegts.c
+++ b/libavformat/mpegts.c
@@ -53,6 +53,10 @@
 (prev_dividend) = (dividend);  
\
 } while (0)
 
+#define PROBE_PACKET_MAX_BUF 8192
+#define PROBE_PACKET_STEP 512
+#define PROBE_PACKET_MARGIN 5
+
 enum MpegTSFilterType {
 MPEGTS_PES,
 MPEGTS_SECTION,
@@ -591,28 +595,42 @@ static int analyze(const uint8_t *buf, int size, int 
packet_size,
 return best_score - FFMAX(stat_all - 10*best_score, 0)/10;
 }
 
-/* autodetect fec presence. Must have at least 1024 bytes  */
-static int get_packet_size(const uint8_t *buf, int size)
+/* autodetect fec presence */
+static int get_packet_size(AVIOContext* pb)
 {
 int score, fec_score, dvhs_score;
+int margin;
+int ret;
 
-if (size < (TS_FEC_PACKET_SIZE * 5 + 1))
-return AVERROR_INVALIDDATA;
+/*init buffer to store stream for probing */
+uint8_t buf[PROBE_PACKET_MAX_BUF] = {0};
+int buf_size = 0;
 
-score  = analyze(buf, size, TS_PACKET_SIZE,  0);
-dvhs_score = analyze(buf, size, TS_DVHS_PACKET_SIZE, 0);
-fec_score  = analyze(buf, size, TS_FEC_PACKET_SIZE,  0);
-av_log(NULL, AV_LOG_TRACE, "score: %d, dvhs_score: %d, fec_score: %d \n",
-score, dvhs_score, fec_score);
-
-if (score > fec_score && score > dvhs_score)
-return TS_PACKET_SIZE;
-else if (dvhs_score > score && dvhs_score > fec_score)
-return TS_DVHS_PACKET_SIZE;
-else if (score < fec_score && dvhs_score < fec_score)
-return TS_FEC_PACKET_SIZE;
-else
-return AVERROR_INVALIDDATA;
+while (buf_size + PROBE_PACKET_STEP <= PROBE_PACKET_MAX_BUF) {
+ret = avio_read(pb, buf + buf_size, PROBE_PACKET_STEP);
+if (ret != PROBE_PACKET_STEP)
+return AVERROR_INVALIDDATA;
+buf_size += ret;
+
+score  = analyze(buf, buf_size, TS_PACKET_SIZE,  0);
+dvhs_score = analyze(buf, buf_size, TS_DVHS_PACKET_SIZE, 0);
+fec_score  = analyze(buf, buf_size, TS_FEC_PACKET_SIZE,  0);
+av_log(NULL, AV_LOG_TRACE, "Probe: %d, score: %d, dvhs_score: %d, 
fec_score: %d \n",
+buf_size, score, dvhs_score, fec_score);
+
+if (buf_size < PROBE_PACKET_MAX_BUF)
+margin = PROBE_PACKET_MARGIN; /*if buffer not filled */
+else
+margin = 0;
+
+if (score > FFMAX(fec_score, dvhs_score) + margin)
+return TS_PACKET_SIZE;
+else if (dvhs_score > FFMAX(score, fec_score) + margin)
+return TS_DVHS_PACKET_SIZE;
+else if (fec_score > FFMAX(score, dvhs_score) + margin)
+return TS_FEC_PACKET_SIZE;
+}
+return AVERROR_INVALIDDATA;
 }
 
 typedef struct SectionHeader {
@@ -2841,8 +2859,6 @@ static int mpegts_read_header(AVFormatContext *s)
 {
 MpegTSContext *ts = s->priv_data;
 AVIOContext *pb   = s->pb;
-uint8_t buf[8 * 1024] = {0};
-int len;
 int64_t pos, probesize = s->probesize;
 
 s->internal->prefer_codec_framerate = 1;
@@ -2850,10 +2866,8 @@ static int mpegts_read_header(AVFormatContext *s)
 if (ffio_ensure_seekback(pb, probesize) < 0)
 av_log(s, AV_LOG_WARNING, "Failed to allocate buffers for seekback\n");
 
-/* read the first 8192 bytes to get packet size */
 pos = avio_tell(pb);
-len = avio_read(pb, buf, sizeof(buf));
-ts->raw_packet_size = get_packet_size(buf, len);
+ts->raw_packet_size = get_packet_size(pb);
 if (ts->raw_packet_size <= 0) {
 av_log(s, AV_LOG_WARNING, "Could not detect TS packet size, defaulting 
to non-FEC/DVHS\n");
 ts->raw_packet_size = TS_PACKET_SIZE;
-- 
2.20.1

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


Re: [FFmpeg-devel] [PATCH 3/4] lavfi/nlmeans: Checking number precision when computing integral images

2019-03-06 Thread myp...@gmail.com
On Wed, Mar 6, 2019 at 9:15 PM Carl Eugen Hoyos  wrote:
>
> 2019-03-06 12:31 GMT+01:00, myp...@gmail.com :
> > On Wed, Mar 6, 2019 at 3:55 PM Carl Eugen Hoyos 
wrote:
> >>
> >> 2019-03-06 4:18 GMT+01:00, Jun Zhao :
>
> >> > +// accumulation of 8-bits uint_8 (uint8_t *src) into 32-bits
> >> > (uint32_t *ii)
> >> > +// data type, it will have a risk of an integral value becoming
> >> > larger than
> >> > +// the 32-bits integer capacity and resulting in an integer
> >> > overflow.
> >> > +if ((w * h * UINT8_MAX) > UINT32_MAX)
> >>
> >> I don't think UINT8_MAX increases readability and I suspect
> >> this should contain "UINT32_MAX / (w*h)" or similar on
> >> one side.
> >>
> > You means like: UINT32_MAX/w < (UINT8_MAX * h) ?
>
> Actually: (UINT32_MAX / w < 255 * h)
> (But that may only be me)
>
Update V3 patch for this check in https://patchwork.ffmpeg.org/patch/12230/,
Tks
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH V3] lavfi/nlmeans: Checking number precision when computing integral images

2019-03-06 Thread Jun Zhao
From: Jun Zhao 

accumulation of 8-bits uint_8 (uint8_t *src) into 32-bits (uint32_t *ii)
data type, it will have a risk of an integral value becoming larger than
the 32-bits integer capacity and resulting in an integer overflow. For
this risk, add a checking with warning message.

Signed-off-by: Jun Zhao 
---
 libavfilter/vf_nlmeans.c |7 +++
 1 files changed, 7 insertions(+), 0 deletions(-)

diff --git a/libavfilter/vf_nlmeans.c b/libavfilter/vf_nlmeans.c
index dcb5a03..9876aae 100644
--- a/libavfilter/vf_nlmeans.c
+++ b/libavfilter/vf_nlmeans.c
@@ -236,6 +236,13 @@ static void compute_ssd_integral_image(const 
NLMeansDSPContext *dsp,
 // adjusted end x position of the safe area after width of the safe area 
gets aligned
 const int endx_safe = startx_safe + safe_pw;
 
+// accumulation of 8-bits uint_8 (uint8_t *src) into 32-bits (uint32_t *ii)
+// data type, it will have a risk of an integral value becoming larger than
+// the 32-bits integer capacity and resulting in an integer overflow.
+if ((UINT32_MAX / (uint64_t)w) < (255 * (uint64_t)h))
+av_log(NULL, AV_LOG_WARNING,
+   "image (%d x %d) integral value may overflow.\n", w ,h);
+
 // top part where only one of s1 and s2 is still readable, or none at all
 compute_unsafe_ssd_integral_image(ii, ii_linesize_32,
   0, 0,
-- 
1.7.1

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


Re: [FFmpeg-devel] [PATCH V2] lavfi/nlmeans: Checking number precision when computing integral images

2019-03-06 Thread myp...@gmail.com
On Thu, Mar 7, 2019 at 9:39 AM Jun Zhao  wrote:
>
> From: Jun Zhao 
>
> accumulation of 8-bits uint_8 (uint8_t *src) into 32-bits (uint32_t *ii)
> data type, it will have a risk of an integral value becoming larger than
> the 32-bits integer capacity and resulting in an integer overflow. For
> this risk, add a checking with warning message.
>
> Signed-off-by: Jun Zhao 
> ---
>  libavfilter/vf_nlmeans.c |7 +++
>  1 files changed, 7 insertions(+), 0 deletions(-)
>
> diff --git a/libavfilter/vf_nlmeans.c b/libavfilter/vf_nlmeans.c
> index dcb5a03..e7015cd 100644
> --- a/libavfilter/vf_nlmeans.c
> +++ b/libavfilter/vf_nlmeans.c
> @@ -236,6 +236,13 @@ static void compute_ssd_integral_image(const 
> NLMeansDSPContext *dsp,
>  // adjusted end x position of the safe area after width of the safe area 
> gets aligned
>  const int endx_safe = startx_safe + safe_pw;
>
> +// accumulation of 8-bits uint_8 (uint8_t *src) into 32-bits (uint32_t 
> *ii)
> +// data type, it will have a risk of an integral value becoming larger 
> than
> +// the 32-bits integer capacity and resulting in an integer overflow.
> +if ((UINT32_MAX / (uint64_t)w) < (UINT8_MAX * (uint64_t)h))
> +av_log(NULL, AV_LOG_WARNING,
> +   "image (%d x %d) integral value maybe overflow.\n", w ,h);
> +
>  // top part where only one of s1 and s2 is still readable, or none at all
>  compute_unsafe_ssd_integral_image(ii, ii_linesize_32,
>0, 0,
> --
> 1.7.1
Pls ignore this patch, send a wrong patch
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH V2] lavfi/nlmeans: Checking number precision when computing integral images

2019-03-06 Thread Jun Zhao
From: Jun Zhao 

accumulation of 8-bits uint_8 (uint8_t *src) into 32-bits (uint32_t *ii)
data type, it will have a risk of an integral value becoming larger than
the 32-bits integer capacity and resulting in an integer overflow. For
this risk, add a checking with warning message.

Signed-off-by: Jun Zhao 
---
 libavfilter/vf_nlmeans.c |7 +++
 1 files changed, 7 insertions(+), 0 deletions(-)

diff --git a/libavfilter/vf_nlmeans.c b/libavfilter/vf_nlmeans.c
index dcb5a03..e7015cd 100644
--- a/libavfilter/vf_nlmeans.c
+++ b/libavfilter/vf_nlmeans.c
@@ -236,6 +236,13 @@ static void compute_ssd_integral_image(const 
NLMeansDSPContext *dsp,
 // adjusted end x position of the safe area after width of the safe area 
gets aligned
 const int endx_safe = startx_safe + safe_pw;
 
+// accumulation of 8-bits uint_8 (uint8_t *src) into 32-bits (uint32_t *ii)
+// data type, it will have a risk of an integral value becoming larger than
+// the 32-bits integer capacity and resulting in an integer overflow.
+if ((UINT32_MAX / (uint64_t)w) < (UINT8_MAX * (uint64_t)h))
+av_log(NULL, AV_LOG_WARNING,
+   "image (%d x %d) integral value maybe overflow.\n", w ,h);
+
 // top part where only one of s1 and s2 is still readable, or none at all
 compute_unsafe_ssd_integral_image(ii, ii_linesize_32,
   0, 0,
-- 
1.7.1

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


Re: [FFmpeg-devel] [PATCH] Added more commandline options for libaom encoder.

2019-03-06 Thread James Almer
On 3/6/2019 9:56 PM, Sam John wrote:
> The following are the newly added options:
> arnr_max_frames, arnr_strength, aq_mode, denoise_noise_level, 
> denoise_block_size,
> rc_undershoot_pct, rc_overshoot_pct, minsection_pct, maxsection_pct, 
> frame_parallel,
> enable_cdef, and enable_global_motion.

We're currently allowing compilation of libavcodec with libaom 1.0.0 as
the oldest version. If any of these options or aom_codec_enc_cfg entries
were added after 1.0.0 was tagged, then you need to wrap the relevant
lines in ctlidstr[] and aom_init() with the related AOM_CTRL_*,
AOM_ENCODER_ABI_VERSION, or whichever preprocessor check.

> ---
>  libavcodec/libaomenc.c | 71 --
>  1 file changed, 68 insertions(+), 3 deletions(-)
> 
> diff --git a/libavcodec/libaomenc.c b/libavcodec/libaomenc.c
> index faec61cacd..687ea5f2c7 100644
> --- a/libavcodec/libaomenc.c
> +++ b/libavcodec/libaomenc.c
> @@ -66,36 +66,57 @@ typedef struct AOMEncoderContext {
>  struct FrameListData *coded_frame_list;
>  int cpu_used;
>  int auto_alt_ref;
> +int arnr_max_frames;
> +int arnr_strength;
> +int aq_mode;
>  int lag_in_frames;
>  int error_resilient;
>  int crf;
>  int static_thresh;
>  int drop_threshold;
> +int denoise_noise_level;
> +int denoise_block_size;
>  uint64_t sse[4];
>  int have_sse; /**< true if we have pending sse[] */
>  uint64_t frame_number;
> +int rc_undershoot_pct;
> +int rc_overshoot_pct;
> +int minsection_pct;
> +int maxsection_pct;
> +int frame_parallel;
>  int tile_cols, tile_rows;
>  int tile_cols_log2, tile_rows_log2;
>  aom_superblock_size_t superblock_size;
>  int uniform_tiles;
>  int row_mt;
> +int enable_cdef;
> +int enable_global_motion;
>  } AOMContext;
>  
>  static const char *const ctlidstr[] = {
>  [AOME_SET_CPUUSED]  = "AOME_SET_CPUUSED",
>  [AOME_SET_CQ_LEVEL] = "AOME_SET_CQ_LEVEL",
>  [AOME_SET_ENABLEAUTOALTREF] = "AOME_SET_ENABLEAUTOALTREF",
> +[AOME_SET_ARNR_MAXFRAMES]   = "AOME_SET_ARNR_MAXFRAMES",
> +[AOME_SET_ARNR_STRENGTH]= "AOME_SET_ARNR_STRENGTH",
>  [AOME_SET_STATIC_THRESHOLD] = "AOME_SET_STATIC_THRESHOLD",
>  [AV1E_SET_COLOR_RANGE]  = "AV1E_SET_COLOR_RANGE",
>  [AV1E_SET_COLOR_PRIMARIES]  = "AV1E_SET_COLOR_PRIMARIES",
> +[AV1E_SET_DENOISE_NOISE_LEVEL] = "AV1E_SET_DENOISE_NOISE_LEVEL",
> +[AV1E_SET_DENOISE_BLOCK_SIZE] = "AV1E_SET_DENOISE_BLOCK_SIZE",
>  [AV1E_SET_MATRIX_COEFFICIENTS] = "AV1E_SET_MATRIX_COEFFICIENTS",
>  [AV1E_SET_TRANSFER_CHARACTERISTICS] = 
> "AV1E_SET_TRANSFER_CHARACTERISTICS",
> +[AV1E_SET_AQ_MODE]  = "AV1E_SET_AQ_MODE",
> +[AV1E_SET_FRAME_PARALLEL_DECODING] = "AV1E_SET_FRAME_PARALLEL_DECODING",
>  [AV1E_SET_SUPERBLOCK_SIZE]  = "AV1E_SET_SUPERBLOCK_SIZE",
>  [AV1E_SET_TILE_COLUMNS] = "AV1E_SET_TILE_COLUMNS",
>  [AV1E_SET_TILE_ROWS]= "AV1E_SET_TILE_ROWS",
> +[AV1E_SET_MAX_REFERENCE_FRAMES] = "AV1E_SET_MAX_REFERENCE_FRAMES",
>  #ifdef AOM_CTRL_AV1E_SET_ROW_MT
>  [AV1E_SET_ROW_MT]   = "AV1E_SET_ROW_MT",
>  #endif
> +[AV1E_SET_ENABLE_CDEF]  = "AV1E_SET_ENABLE_CDEF",
> +[AV1E_SET_ENABLE_GLOBAL_MOTION] = "AV1E_SET_ENABLE_GLOBAL_MOTION",
>  };
>  
>  static av_cold void log_encoder_error(AVCodecContext *avctx, const char 
> *desc)
> @@ -567,10 +588,14 @@ static av_cold int aom_init(AVCodecContext *avctx,
>  
>  // 0-100 (0 => CBR, 100 => VBR)
>  enccfg.rc_2pass_vbr_bias_pct   = round(avctx->qcompress * 100);
> -if (avctx->bit_rate)
> +if (ctx->minsection_pct >= 0)
> +enccfg.rc_2pass_vbr_minsection_pct = ctx->minsection_pct;
> +else if (avctx->bit_rate)
>  enccfg.rc_2pass_vbr_minsection_pct =
>  avctx->rc_min_rate * 100LL / avctx->bit_rate;
> -if (avctx->rc_max_rate)
> +if (ctx->maxsection_pct >= 0)
> +enccfg.rc_2pass_vbr_maxsection_pct = ctx->maxsection_pct;
> +else if (avctx->rc_max_rate)
>  enccfg.rc_2pass_vbr_maxsection_pct =
>  avctx->rc_max_rate * 100LL / avctx->bit_rate;
>  
> @@ -582,6 +607,11 @@ static av_cold int aom_init(AVCodecContext *avctx,
>  avctx->rc_initial_buffer_occupancy * 1000LL / avctx->bit_rate;
>  enccfg.rc_buf_optimal_sz = enccfg.rc_buf_sz * 5 / 6;
>  
> +if (ctx->rc_undershoot_pct >= 0)
> +enccfg.rc_undershoot_pct = ctx->rc_undershoot_pct;
> +if (ctx->rc_overshoot_pct >= 0)
> +enccfg.rc_overshoot_pct = ctx->rc_overshoot_pct;
> +
>  // _enc_init() will balk if kf_min_dist differs from max w/AOM_KF_AUTO
>  if (avctx->keyint_min >= 0 && avctx->keyint_min == avctx->gop_size)
>  enccfg.kf_min_dist = avctx->keyint_min;
> @@ -643,14 +673,30 @@ static av_cold int aom_init(AVCodecContext *avctx,
>  codecctl_int(avctx, AOME_SET_CPUUSED, ctx->cpu_used);
>  if (ctx->auto_alt_ref >= 0)
>  

[FFmpeg-devel] [PATCH] Added more commandline options for libaom encoder.

2019-03-06 Thread Sam John
The following are the newly added options:
arnr_max_frames, arnr_strength, aq_mode, denoise_noise_level, 
denoise_block_size,
rc_undershoot_pct, rc_overshoot_pct, minsection_pct, maxsection_pct, 
frame_parallel,
enable_cdef, and enable_global_motion.
---
 libavcodec/libaomenc.c | 71 --
 1 file changed, 68 insertions(+), 3 deletions(-)

diff --git a/libavcodec/libaomenc.c b/libavcodec/libaomenc.c
index faec61cacd..687ea5f2c7 100644
--- a/libavcodec/libaomenc.c
+++ b/libavcodec/libaomenc.c
@@ -66,36 +66,57 @@ typedef struct AOMEncoderContext {
 struct FrameListData *coded_frame_list;
 int cpu_used;
 int auto_alt_ref;
+int arnr_max_frames;
+int arnr_strength;
+int aq_mode;
 int lag_in_frames;
 int error_resilient;
 int crf;
 int static_thresh;
 int drop_threshold;
+int denoise_noise_level;
+int denoise_block_size;
 uint64_t sse[4];
 int have_sse; /**< true if we have pending sse[] */
 uint64_t frame_number;
+int rc_undershoot_pct;
+int rc_overshoot_pct;
+int minsection_pct;
+int maxsection_pct;
+int frame_parallel;
 int tile_cols, tile_rows;
 int tile_cols_log2, tile_rows_log2;
 aom_superblock_size_t superblock_size;
 int uniform_tiles;
 int row_mt;
+int enable_cdef;
+int enable_global_motion;
 } AOMContext;
 
 static const char *const ctlidstr[] = {
 [AOME_SET_CPUUSED]  = "AOME_SET_CPUUSED",
 [AOME_SET_CQ_LEVEL] = "AOME_SET_CQ_LEVEL",
 [AOME_SET_ENABLEAUTOALTREF] = "AOME_SET_ENABLEAUTOALTREF",
+[AOME_SET_ARNR_MAXFRAMES]   = "AOME_SET_ARNR_MAXFRAMES",
+[AOME_SET_ARNR_STRENGTH]= "AOME_SET_ARNR_STRENGTH",
 [AOME_SET_STATIC_THRESHOLD] = "AOME_SET_STATIC_THRESHOLD",
 [AV1E_SET_COLOR_RANGE]  = "AV1E_SET_COLOR_RANGE",
 [AV1E_SET_COLOR_PRIMARIES]  = "AV1E_SET_COLOR_PRIMARIES",
+[AV1E_SET_DENOISE_NOISE_LEVEL] = "AV1E_SET_DENOISE_NOISE_LEVEL",
+[AV1E_SET_DENOISE_BLOCK_SIZE] = "AV1E_SET_DENOISE_BLOCK_SIZE",
 [AV1E_SET_MATRIX_COEFFICIENTS] = "AV1E_SET_MATRIX_COEFFICIENTS",
 [AV1E_SET_TRANSFER_CHARACTERISTICS] = "AV1E_SET_TRANSFER_CHARACTERISTICS",
+[AV1E_SET_AQ_MODE]  = "AV1E_SET_AQ_MODE",
+[AV1E_SET_FRAME_PARALLEL_DECODING] = "AV1E_SET_FRAME_PARALLEL_DECODING",
 [AV1E_SET_SUPERBLOCK_SIZE]  = "AV1E_SET_SUPERBLOCK_SIZE",
 [AV1E_SET_TILE_COLUMNS] = "AV1E_SET_TILE_COLUMNS",
 [AV1E_SET_TILE_ROWS]= "AV1E_SET_TILE_ROWS",
+[AV1E_SET_MAX_REFERENCE_FRAMES] = "AV1E_SET_MAX_REFERENCE_FRAMES",
 #ifdef AOM_CTRL_AV1E_SET_ROW_MT
 [AV1E_SET_ROW_MT]   = "AV1E_SET_ROW_MT",
 #endif
+[AV1E_SET_ENABLE_CDEF]  = "AV1E_SET_ENABLE_CDEF",
+[AV1E_SET_ENABLE_GLOBAL_MOTION] = "AV1E_SET_ENABLE_GLOBAL_MOTION",
 };
 
 static av_cold void log_encoder_error(AVCodecContext *avctx, const char *desc)
@@ -567,10 +588,14 @@ static av_cold int aom_init(AVCodecContext *avctx,
 
 // 0-100 (0 => CBR, 100 => VBR)
 enccfg.rc_2pass_vbr_bias_pct   = round(avctx->qcompress * 100);
-if (avctx->bit_rate)
+if (ctx->minsection_pct >= 0)
+enccfg.rc_2pass_vbr_minsection_pct = ctx->minsection_pct;
+else if (avctx->bit_rate)
 enccfg.rc_2pass_vbr_minsection_pct =
 avctx->rc_min_rate * 100LL / avctx->bit_rate;
-if (avctx->rc_max_rate)
+if (ctx->maxsection_pct >= 0)
+enccfg.rc_2pass_vbr_maxsection_pct = ctx->maxsection_pct;
+else if (avctx->rc_max_rate)
 enccfg.rc_2pass_vbr_maxsection_pct =
 avctx->rc_max_rate * 100LL / avctx->bit_rate;
 
@@ -582,6 +607,11 @@ static av_cold int aom_init(AVCodecContext *avctx,
 avctx->rc_initial_buffer_occupancy * 1000LL / avctx->bit_rate;
 enccfg.rc_buf_optimal_sz = enccfg.rc_buf_sz * 5 / 6;
 
+if (ctx->rc_undershoot_pct >= 0)
+enccfg.rc_undershoot_pct = ctx->rc_undershoot_pct;
+if (ctx->rc_overshoot_pct >= 0)
+enccfg.rc_overshoot_pct = ctx->rc_overshoot_pct;
+
 // _enc_init() will balk if kf_min_dist differs from max w/AOM_KF_AUTO
 if (avctx->keyint_min >= 0 && avctx->keyint_min == avctx->gop_size)
 enccfg.kf_min_dist = avctx->keyint_min;
@@ -643,14 +673,30 @@ static av_cold int aom_init(AVCodecContext *avctx,
 codecctl_int(avctx, AOME_SET_CPUUSED, ctx->cpu_used);
 if (ctx->auto_alt_ref >= 0)
 codecctl_int(avctx, AOME_SET_ENABLEAUTOALTREF, ctx->auto_alt_ref);
-
+if (ctx->arnr_max_frames >= 0)
+codecctl_int(avctx, AOME_SET_ARNR_MAXFRAMES,   ctx->arnr_max_frames);
+if (ctx->arnr_strength >= 0)
+codecctl_int(avctx, AOME_SET_ARNR_STRENGTH,ctx->arnr_strength);
+if (ctx->enable_cdef >= 0)
+codecctl_int(avctx, AV1E_SET_ENABLE_CDEF, ctx->enable_cdef);
+if (ctx->enable_global_motion >= 0)
+codecctl_int(avctx, AV1E_SET_ENABLE_GLOBAL_MOTION, 
ctx->enable_global_motion);
 codecctl_int(avctx, AOME_SET_STATIC_THRESHOLD, ctx->static_thresh);
 if 

Re: [FFmpeg-devel] [PATCH] lavc/h264_levels: add MaxMBPS checking and update fate test.

2019-03-06 Thread Mark Thompson
On 06/03/2019 08:21, Decai Lin wrote:
> 1. add MaxMBPS checking for level idc setting to align with AVC spec
>AnnexA table A-1/A-6 level limits.
> 2. update h264 level fate test.
> 
> Signed-off-by: Decai Lin 
> ---
>  libavcodec/h264_levels.c   |  5 +
>  libavcodec/h264_levels.h   |  1 +
>  libavcodec/h264_metadata_bsf.c | 14 +-
>  libavcodec/tests/h264_levels.c | 41 ++---
>  libavcodec/vaapi_encode_h264.c | 13 +
>  5 files changed, 70 insertions(+), 4 deletions(-)

Nice, this is a good idea.  Some comments below.

> diff --git a/libavcodec/h264_levels.c b/libavcodec/h264_levels.c
> index 7a55116..e457dbe 100644
> --- a/libavcodec/h264_levels.c
> +++ b/libavcodec/h264_levels.c
> @@ -89,11 +89,13 @@ const H264LevelDescriptor *ff_h264_get_level(int 
> level_idc,
>  
>  const H264LevelDescriptor *ff_h264_guess_level(int profile_idc,
> int64_t bitrate,
> +   int framerate,
> int width, int height,
> int max_dec_frame_buffering)
>  {
>  int width_mbs  = (width  + 15) / 16;
>  int height_mbs = (height + 15) / 16;
> +int64_t mb_processing_rate = (int64_t) (width_mbs * height_mbs * 
> framerate);

This doesn't work - if it overflows you've already hit undefined behaviour in 
the calculation before the cast.

>  int no_cs3f = !(profile_idc == 66 ||
>  profile_idc == 77 ||
>  profile_idc == 88);
> @@ -108,6 +110,9 @@ const H264LevelDescriptor *ff_h264_guess_level(int 
> profile_idc,
>  if (bitrate > (int64_t)level->max_br * 
> h264_get_br_factor(profile_idc))
>  continue;
>  
> +if (mb_processing_rate > (int64_t)level->max_mbps)
> +continue;
> +
>  if (width_mbs  * height_mbs > level->max_fs)
>  continue;
>  if (width_mbs  * width_mbs  > 8 * level->max_fs)
> diff --git a/libavcodec/h264_levels.h b/libavcodec/h264_levels.h
> index 4189fc6..0a0f410 100644
> --- a/libavcodec/h264_levels.h
> +++ b/libavcodec/h264_levels.h
> @@ -46,6 +46,7 @@ const H264LevelDescriptor *ff_h264_get_level(int level_idc,
>   */
>  const H264LevelDescriptor *ff_h264_guess_level(int profile_idc,
> int64_t bitrate,
> +   int framerate,
> int width, int height,
> int max_dec_frame_buffering);
>  
> diff --git a/libavcodec/h264_metadata_bsf.c b/libavcodec/h264_metadata_bsf.c
> index a17987a..61c2711 100644
> --- a/libavcodec/h264_metadata_bsf.c
> +++ b/libavcodec/h264_metadata_bsf.c
> @@ -223,6 +223,7 @@ static int h264_metadata_update_sps(AVBSFContext *bsf,
>  const H264LevelDescriptor *desc;
>  int64_t bit_rate;
>  int width, height, dpb_frames;
> +int framerate, fr_num, fr_den;
>  
>  if (sps->vui.nal_hrd_parameters_present_flag) {
>  bit_rate = 
> (sps->vui.nal_hrd_parameters.bit_rate_value_minus1[0] + 1) *
> @@ -244,7 +245,18 @@ static int h264_metadata_update_sps(AVBSFContext *bsf,
>  height = 16 * (sps->pic_height_in_map_units_minus1 + 1) *
>  (2 - sps->frame_mbs_only_flag);
>  
> -desc = ff_h264_guess_level(sps->profile_idc, bit_rate,
> +if (ctx->tick_rate.num > 0 && ctx->tick_rate.den > 0)
> +av_reduce(_num, _den,
> +ctx->tick_rate.num, ctx->tick_rate.den, 65535);
> +else
> +av_reduce(_num, _den,
> +ctx->tick_rate.den, ctx->tick_rate.num, 65535);

Since the VUI fields are set above, I suggest using them instead here because 
that will include an existing rate in the stream.

Also, the tick rate is only directly usable as fieldrate if 
fixed_frame_rate_flag is set.

> +if (fr_den > 0)
> +framerate = fr_num / fr_den;
> +else
> +framerate = fr_num;

I'm not sure what this is trying to do.  If the number isn't valid, the 
framerate should be passed as zero to avoid constraining anything.

> +
> +desc = ff_h264_guess_level(sps->profile_idc, bit_rate, framerate,
> width, height, dpb_frames);
>  if (desc) {
>  level_idc = desc->level_idc;
> diff --git a/libavcodec/tests/h264_levels.c b/libavcodec/tests/h264_levels.c
> index 0e00f05..6176c0b 100644
> --- a/libavcodec/tests/h264_levels.c
> +++ b/libavcodec/tests/h264_levels.c
> @@ -62,6 +62,31 @@ static const struct {
>  static const struct {
>  int width;
>  int height;
> +int framerate;
> +int level_idc;
> +} test_framerate[] = {
> +// Some typical sizes and 

Re: [FFmpeg-devel] [PATCH 2/2] configure: use vpx_codec_vp8_dx/cx for libvpx-vp8 checking

2019-03-06 Thread James Zern
On Mon, Mar 4, 2019 at 6:19 AM Guo, Yejun  wrote:
>
> Signed-off-by: Guo, Yejun 
> ---
>  configure | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>

lgtm. This is a remnant from when vp8 was the only codec in the library.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] Patch for vf_fillborders.c – Bug?

2019-03-06 Thread Ulf Zibis
Hi,

I think there is a bug in vf_fillborders.c 16 bit routines.

When using memset or memcopy, I think, correct linesize instead
s->planewidth[p] should be used.
When using arrray syntax, I think, correct s->planewidth[p] instead
linesize should be used.

See my proposed patch.

-Ulf

>From f3513f992e0b5595f2644257b92fdea6189592de Mon Sep 17 00:00:00 2001
From: Ulf Zibis 
Date: 07.03.2019, 00:34:51

Correct usage of linesize and width in 16 bit depth routines.

diff --git a/.gitignore b/.gitignore
index 0e57cb0..7819c84 100644
--- a/.gitignore
+++ b/.gitignore
@@ -36,3 +36,5 @@
 /lcov/
 /src
 /mapfile
+/nbproject
+/debug
diff --git a/libavfilter/vf_fillborders.c b/libavfilter/vf_fillborders.c
index 1344587..019cdff 100644
--- a/libavfilter/vf_fillborders.c
+++ b/libavfilter/vf_fillborders.c
@@ -89,25 +89,27 @@
 for (p = 0; p < s->nb_planes; p++) {
 uint8_t *ptr = frame->data[p];
 int linesize = frame->linesize[p];
+int nb_leftbytes = s->borders[p].left * linesize / s->planewidth[p];
+int nb_rightbytes = s->borders[p].right * linesize / s->planewidth[p];
 
 for (y = s->borders[p].top; y < s->planeheight[p] - s->borders[p].bottom; y++) {
 memset(ptr + y * linesize,
-   *(ptr + y * linesize + s->borders[p].left),
-   s->borders[p].left);
-memset(ptr + y * linesize + s->planewidth[p] - s->borders[p].right,
-   *(ptr + y * linesize + s->planewidth[p] - s->borders[p].right - 1),
-   s->borders[p].right);
+   *(ptr + y * linesize + nb_leftbytes),
+   nb_leftbytes);
+memset(ptr + y * linesize + linesize - nb_rightbytes,
+   *(ptr + y * linesize + linesize - nb_rightbytes - 1),
+   nb_rightbytes);
 }
 
 for (y = 0; y < s->borders[p].top; y++) {
 memcpy(ptr + y * linesize,
-   ptr + s->borders[p].top * linesize, s->planewidth[p]);
+   ptr + s->borders[p].top * linesize, linesize);
 }
 
 for (y = s->planeheight[p] - s->borders[p].bottom; y < s->planeheight[p]; y++) {
 memcpy(ptr + y * linesize,
ptr + (s->planeheight[p] - s->borders[p].bottom - 1) * linesize,
-   s->planewidth[p]);
+   linesize);
 }
 }
 }
@@ -118,28 +120,28 @@
 
 for (p = 0; p < s->nb_planes; p++) {
 uint16_t *ptr = (uint16_t *)frame->data[p];
-int linesize = frame->linesize[p] / 2;
+int linesize = frame->linesize[p];
 
 for (y = s->borders[p].top; y < s->planeheight[p] - s->borders[p].bottom; y++) {
 for (x = 0; x < s->borders[p].left; x++) {
-ptr[y * linesize + x] =  *(ptr + y * linesize + s->borders[p].left);
+ptr[y * s->planewidth[p] + x] =  *(ptr + y * s->planewidth[p] + s->borders[p].left);
 }
 
 for (x = 0; x < s->borders[p].right; x++) {
-ptr[y * linesize + s->planewidth[p] - s->borders[p].right + x] =
-   *(ptr + y * linesize + s->planewidth[p] - s->borders[p].right - 1);
+ptr[y * s->planewidth[p] + s->planewidth[p] - s->borders[p].right + x] =
+   *(ptr + y * s->planewidth[p] + s->planewidth[p] - s->borders[p].right - 1);
 }
 }
 
 for (y = 0; y < s->borders[p].top; y++) {
 memcpy(ptr + y * linesize,
-   ptr + s->borders[p].top * linesize, s->planewidth[p] * 2);
+   ptr + s->borders[p].top * linesize, linesize);
 }
 
 for (y = s->planeheight[p] - s->borders[p].bottom; y < s->planeheight[p]; y++) {
 memcpy(ptr + y * linesize,
ptr + (s->planeheight[p] - s->borders[p].bottom - 1) * linesize,
-   s->planewidth[p] * 2);
+   linesize);
 }
 }
 }
@@ -154,25 +156,25 @@
 
 for (y = s->borders[p].top; y < s->planeheight[p] - s->borders[p].bottom; y++) {
 for (x = 0; x < s->borders[p].left; x++) {
-ptr[y * linesize + x] = ptr[y * linesize + s->borders[p].left * 2 - 1 - x];
+ptr[y * s->planewidth[p] + x] = ptr[y * s->planewidth[p] + s->borders[p].left * 2 - 1 - x];
 }
 
 for (x = 0; x < s->borders[p].right; x++) {
-ptr[y * linesize + s->planewidth[p] - s->borders[p].right + x] =
-ptr[y * linesize + s->planewidth[p] - s->borders[p].right - 1 - x];
+ptr[y * s->planewidth[p] + s->planewidth[p] - s->borders[p].right + x] =
+ptr[y * s->planewidth[p] + s->planewidth[p] - s->borders[p].right - 1 - x];
 }
 }
 
 for (y = 0; y < s->borders[p].top; y++) {
 memcpy(ptr + y * linesize,
ptr + (s->borders[p].top * 2 - 1 - y) * linesize,
-   s->planewidth[p]);
+   

Re: [FFmpeg-devel] [PATCH v2] avformat/mpegts: reduce buffering during initialization

2019-03-06 Thread Marton Balint



On Wed, 6 Mar 2019, Andriy Gelman wrote:


From: Andriy Gelman 

Reduces buffering latency with low bitrate streams, where
8192 bytes can mean several seconds.
---
libavformat/mpegts.c | 60 +++-
1 file changed, 37 insertions(+), 23 deletions(-)

diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c
index b04fd7b4f4..fcb5b488d8 100644
--- a/libavformat/mpegts.c
+++ b/libavformat/mpegts.c
@@ -53,6 +53,10 @@
(prev_dividend) = (dividend);  \
} while (0)

+#define PROBE_PACKET_MAX_BUF 8192
+#define PROBE_PACKET_STEP 512
+#define PROBE_PACKET_MARGIN 5
+
enum MpegTSFilterType {
MPEGTS_PES,
MPEGTS_SECTION,
@@ -591,28 +595,42 @@ static int analyze(const uint8_t *buf, int size, int 
packet_size,
return best_score - FFMAX(stat_all - 10*best_score, 0)/10;
}

-/* autodetect fec presence. Must have at least 1024 bytes  */
-static int get_packet_size(const uint8_t *buf, int size)
+/* autodetect fec presence */
+static int get_packet_size(AVIOContext* pb)
{
int score, fec_score, dvhs_score;
+int margin;
+int ret;

-if (size < (TS_FEC_PACKET_SIZE * 5 + 1))
-return AVERROR_INVALIDDATA;
+/*init buffer to store stream for probing */
+uint8_t buf[PROBE_PACKET_MAX_BUF] = {0};
+int buf_size = 0;

-score  = analyze(buf, size, TS_PACKET_SIZE,  0);
-dvhs_score = analyze(buf, size, TS_DVHS_PACKET_SIZE, 0);
-fec_score  = analyze(buf, size, TS_FEC_PACKET_SIZE,  0);
-av_log(NULL, AV_LOG_TRACE, "score: %d, dvhs_score: %d, fec_score: %d \n",
-score, dvhs_score, fec_score);
-
-if (score > fec_score && score > dvhs_score)
-return TS_PACKET_SIZE;
-else if (dvhs_score > score && dvhs_score > fec_score)
-return TS_DVHS_PACKET_SIZE;
-else if (score < fec_score && dvhs_score < fec_score)
-return TS_FEC_PACKET_SIZE;
-else
-return AVERROR_INVALIDDATA;
+while (buf_size + PROBE_PACKET_STEP <= PROBE_PACKET_MAX_BUF) {
+ret = avio_read(pb, buf + buf_size, PROBE_PACKET_STEP);
+if (ret < 0)
+break;


If EOF happens on STEP boundary then you return INVALIDDATA instead 
of comparing last scores with 0 margin...



+buf_size += ret;
+
+score  = analyze(buf, buf_size, TS_PACKET_SIZE,  0);
+dvhs_score = analyze(buf, buf_size, TS_DVHS_PACKET_SIZE, 0);
+fec_score  = analyze(buf, buf_size, TS_FEC_PACKET_SIZE,  0);
+av_log(NULL, AV_LOG_TRACE, "Probe: %d, score: %d, dvhs_score: %d, 
fec_score: %d \n",
+buf_size, score, dvhs_score, fec_score);
+
+if (buf_size < PROBE_PACKET_MAX_BUF && ret == PROBE_PACKET_STEP)
+  margin = PROBE_PACKET_MARGIN; /*if buffer not filled and no eof */
+else
+  margin = 0;
+
+if (score > FFMAX(fec_score, dvhs_score) + margin)
+  return TS_PACKET_SIZE;
+else if (dvhs_score > FFMAX(score, fec_score) + margin)
+  return TS_DVHS_PACKET_SIZE;
+else if (fec_score > FFMAX(score, dvhs_score) + margin)
+  return TS_FEC_PACKET_SIZE;
+}
+return AVERROR_INVALIDDATA;
}

typedef struct SectionHeader {
@@ -2841,8 +2859,6 @@ static int mpegts_read_header(AVFormatContext *s)
{
MpegTSContext *ts = s->priv_data;
AVIOContext *pb   = s->pb;
-uint8_t buf[8 * 1024] = {0};
-int len;
int64_t pos, probesize = s->probesize;

s->internal->prefer_codec_framerate = 1;
@@ -2850,10 +2866,8 @@ static int mpegts_read_header(AVFormatContext *s)
if (ffio_ensure_seekback(pb, probesize) < 0)
av_log(s, AV_LOG_WARNING, "Failed to allocate buffers for seekback\n");

-/* read the first 8192 bytes to get packet size */
pos = avio_tell(pb);
-len = avio_read(pb, buf, sizeof(buf));
-ts->raw_packet_size = get_packet_size(buf, len);
+ts->raw_packet_size = get_packet_size(pb);
if (ts->raw_packet_size <= 0) {
av_log(s, AV_LOG_WARNING, "Could not detect TS packet size, defaulting to 
non-FEC/DVHS\n");
ts->raw_packet_size = TS_PACKET_SIZE;
--


Regards,
Marton
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH 1/2] avcodec/v210dec: move DSP function setting into dedicated function

2019-03-06 Thread James Darnley
Prepare for checkasm test.
---
 libavcodec/v210dec.c | 16 ++--
 libavcodec/v210dec.h |  1 +
 2 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/libavcodec/v210dec.c b/libavcodec/v210dec.c
index ddc5dbe8be..fd8a6b0d78 100644
--- a/libavcodec/v210dec.c
+++ b/libavcodec/v210dec.c
@@ -50,6 +50,13 @@ static void v210_planar_unpack_c(const uint32_t *src, 
uint16_t *y, uint16_t *u,
 }
 }
 
+av_cold void ff_v210dec_init(V210DecContext *s)
+{
+s->unpack_frame = v210_planar_unpack_c;
+if (ARCH_X86)
+ff_v210_x86_init(s);
+}
+
 static av_cold int decode_init(AVCodecContext *avctx)
 {
 V210DecContext *s = avctx->priv_data;
@@ -57,10 +64,8 @@ static av_cold int decode_init(AVCodecContext *avctx)
 avctx->pix_fmt = AV_PIX_FMT_YUV422P10;
 avctx->bits_per_raw_sample = 10;
 
-s->unpack_frame= v210_planar_unpack_c;
-
-if (HAVE_MMX)
-ff_v210_x86_init(s);
+s->aligned_input = 0;
+ff_v210dec_init(s);
 
 return 0;
 }
@@ -102,8 +107,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, 
int *got_frame,
 aligned_input = !((uintptr_t)psrc & 0xf) && !(stride & 0xf);
 if (aligned_input != s->aligned_input) {
 s->aligned_input = aligned_input;
-if (HAVE_MMX)
-ff_v210_x86_init(s);
+ff_v210dec_init(s);
 }
 
 if ((ret = ff_get_buffer(avctx, pic, 0)) < 0)
diff --git a/libavcodec/v210dec.h b/libavcodec/v210dec.h
index 533afc435c..cfdb29da09 100644
--- a/libavcodec/v210dec.h
+++ b/libavcodec/v210dec.h
@@ -31,6 +31,7 @@ typedef struct {
 void (*unpack_frame)(const uint32_t *src, uint16_t *y, uint16_t *u, 
uint16_t *v, int width);
 } V210DecContext;
 
+void ff_v210dec_init(V210DecContext *s);
 void ff_v210_x86_init(V210DecContext *s);
 
 #endif /* AVCODEC_V210DEC_H */
-- 
2.20.1

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


[FFmpeg-devel] [PATCH 2/2] checkasm: add test for v210dec

2019-03-06 Thread James Darnley
---
 tests/checkasm/Makefile   |  1 +
 tests/checkasm/checkasm.c |  3 ++
 tests/checkasm/checkasm.h |  1 +
 tests/checkasm/v210dec.c  | 77 +++
 4 files changed, 82 insertions(+)
 create mode 100644 tests/checkasm/v210dec.c

diff --git a/tests/checkasm/Makefile b/tests/checkasm/Makefile
index 47b7b06d28..70abc1a407 100644
--- a/tests/checkasm/Makefile
+++ b/tests/checkasm/Makefile
@@ -25,6 +25,7 @@ AVCODECOBJS-$(CONFIG_JPEG2000_DECODER)  += jpeg2000dsp.o
 AVCODECOBJS-$(CONFIG_PIXBLOCKDSP)   += pixblockdsp.o
 AVCODECOBJS-$(CONFIG_HEVC_DECODER)  += hevc_add_res.o hevc_idct.o 
hevc_sao.o
 AVCODECOBJS-$(CONFIG_UTVIDEO_DECODER)   += utvideodsp.o
+AVCODECOBJS-$(CONFIG_V210_DECODER)  += v210dec.o
 AVCODECOBJS-$(CONFIG_V210_ENCODER)  += v210enc.o
 AVCODECOBJS-$(CONFIG_VP9_DECODER)   += vp9dsp.o
 
diff --git a/tests/checkasm/checkasm.c b/tests/checkasm/checkasm.c
index 9eec41e3c4..bf51e00eab 100644
--- a/tests/checkasm/checkasm.c
+++ b/tests/checkasm/checkasm.c
@@ -136,6 +136,9 @@ static const struct {
 #if CONFIG_UTVIDEO_DECODER
 { "utvideodsp", checkasm_check_utvideodsp },
 #endif
+#if CONFIG_V210_DECODER
+{ "v210dec", checkasm_check_v210dec },
+#endif
 #if CONFIG_V210_ENCODER
 { "v210enc", checkasm_check_v210enc },
 #endif
diff --git a/tests/checkasm/checkasm.h b/tests/checkasm/checkasm.h
index 9e8e879fd3..9b8d2f5419 100644
--- a/tests/checkasm/checkasm.h
+++ b/tests/checkasm/checkasm.h
@@ -69,6 +69,7 @@ void checkasm_check_sbrdsp(void);
 void checkasm_check_synth_filter(void);
 void checkasm_check_sw_rgb(void);
 void checkasm_check_utvideodsp(void);
+void checkasm_check_v210dec(void);
 void checkasm_check_v210enc(void);
 void checkasm_check_vf_hflip(void);
 void checkasm_check_vf_threshold(void);
diff --git a/tests/checkasm/v210dec.c b/tests/checkasm/v210dec.c
new file mode 100644
index 00..7dd50a8271
--- /dev/null
+++ b/tests/checkasm/v210dec.c
@@ -0,0 +1,77 @@
+/*
+ * Copyright (c) 2019 James Darnley
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU 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.
+ */
+
+#include 
+#include "checkasm.h"
+#include "libavcodec/v210dec.h"
+
+static uint32_t get_v210(void)
+{
+uint32_t t0 = rnd() & 0x3ff,
+ t1 = rnd() & 0x3ff,
+ t2 = rnd() & 0x3ff;
+uint32_t value =  t0
+   | (t1 << 10)
+   | (t2 << 20);
+return value;
+}
+
+#define NUM_SAMPLES 2048
+
+static void randomize_buffers(uint32_t *src0, uint32_t *src1, int len)
+{
+for (int i = 0; i < len; i++) {
+uint32_t value = get_v210();
+src0[i] = value;
+src1[i] = value;
+}
+}
+
+void checkasm_check_v210dec(void)
+{
+V210DecContext h;
+
+h.aligned_input = 0;
+ff_v210dec_init();
+
+if (check_func(h.unpack_frame, "v210_unpack")) {
+uint32_t src0[NUM_SAMPLES/3];
+uint32_t src1[NUM_SAMPLES/3];
+uint16_t y0[NUM_SAMPLES/2];
+uint16_t y1[NUM_SAMPLES/2];
+uint16_t u0[NUM_SAMPLES/4];
+uint16_t u1[NUM_SAMPLES/4];
+uint16_t v0[NUM_SAMPLES/4];
+uint16_t v1[NUM_SAMPLES/4];
+declare_func(void, const uint32_t *src, uint16_t *y, uint16_t *u, 
uint16_t *v, int width);
+const int pixels = NUM_SAMPLES / 2 / 6 * 6;
+
+randomize_buffers(src0, src1, NUM_SAMPLES/3);
+call_ref(src0, y0, u0, v0, pixels);
+call_new(src1, y1, u1, v1, pixels);
+if (memcmp(src0, src1, NUM_SAMPLES/3 * sizeof src0[0])
+|| memcmp(y0, y1, pixels * sizeof y0[0])
+|| memcmp(u0, u1, pixels/2 * sizeof u0[0])
+|| memcmp(v0, v1, pixels/2 * sizeof v0[0]))
+fail();
+bench_new(src1, y1, u1, v1, pixels);
+}
+report("v210_unpack");
+}
-- 
2.20.1

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


[FFmpeg-devel] [PATCH] avcodec/v210dec: move DSP function setting into dedicated function

2019-03-06 Thread James Darnley
Prepare for checkasm test.
---
 libavcodec/v210dec.c | 16 ++--
 libavcodec/v210dec.h |  1 +
 2 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/libavcodec/v210dec.c b/libavcodec/v210dec.c
index ddc5dbe8be..6db662538e 100644
--- a/libavcodec/v210dec.c
+++ b/libavcodec/v210dec.c
@@ -50,6 +50,14 @@ static void v210_planar_unpack_c(const uint32_t *src, 
uint16_t *y, uint16_t *u,
 }
 }
 
+av_cold void ff_v210dec_init(V210DecContext *s)
+{
+s->unpack_frame = v210_planar_unpack_c;
+s->aligned_input = 0;
+if (ARCH_X86)
+ff_v210_x86_init(s);
+}
+
 static av_cold int decode_init(AVCodecContext *avctx)
 {
 V210DecContext *s = avctx->priv_data;
@@ -57,10 +65,7 @@ static av_cold int decode_init(AVCodecContext *avctx)
 avctx->pix_fmt = AV_PIX_FMT_YUV422P10;
 avctx->bits_per_raw_sample = 10;
 
-s->unpack_frame= v210_planar_unpack_c;
-
-if (HAVE_MMX)
-ff_v210_x86_init(s);
+ff_v210dec_init(s);
 
 return 0;
 }
@@ -102,8 +107,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, 
int *got_frame,
 aligned_input = !((uintptr_t)psrc & 0xf) && !(stride & 0xf);
 if (aligned_input != s->aligned_input) {
 s->aligned_input = aligned_input;
-if (HAVE_MMX)
-ff_v210_x86_init(s);
+ff_v210dec_init(s);
 }
 
 if ((ret = ff_get_buffer(avctx, pic, 0)) < 0)
diff --git a/libavcodec/v210dec.h b/libavcodec/v210dec.h
index 533afc435c..cfdb29da09 100644
--- a/libavcodec/v210dec.h
+++ b/libavcodec/v210dec.h
@@ -31,6 +31,7 @@ typedef struct {
 void (*unpack_frame)(const uint32_t *src, uint16_t *y, uint16_t *u, 
uint16_t *v, int width);
 } V210DecContext;
 
+void ff_v210dec_init(V210DecContext *s);
 void ff_v210_x86_init(V210DecContext *s);
 
 #endif /* AVCODEC_V210DEC_H */
-- 
2.20.1

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


Re: [FFmpeg-devel] [PATCH] checkasm: add test for v210dec

2019-03-06 Thread James Darnley
On 2019-03-06 20:31, James Darnley wrote:
> ...

Wrong patch and wrong reference.  Please ignore this.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH] checkasm: add test for v210dec

2019-03-06 Thread James Darnley
---
 tests/checkasm/Makefile   |  1 +
 tests/checkasm/checkasm.c |  3 ++
 tests/checkasm/checkasm.h |  1 +
 tests/checkasm/v210dec.c  | 76 +++
 4 files changed, 81 insertions(+)
 create mode 100644 tests/checkasm/v210dec.c

diff --git a/tests/checkasm/Makefile b/tests/checkasm/Makefile
index 47b7b06d28..70abc1a407 100644
--- a/tests/checkasm/Makefile
+++ b/tests/checkasm/Makefile
@@ -25,6 +25,7 @@ AVCODECOBJS-$(CONFIG_JPEG2000_DECODER)  += jpeg2000dsp.o
 AVCODECOBJS-$(CONFIG_PIXBLOCKDSP)   += pixblockdsp.o
 AVCODECOBJS-$(CONFIG_HEVC_DECODER)  += hevc_add_res.o hevc_idct.o 
hevc_sao.o
 AVCODECOBJS-$(CONFIG_UTVIDEO_DECODER)   += utvideodsp.o
+AVCODECOBJS-$(CONFIG_V210_DECODER)  += v210dec.o
 AVCODECOBJS-$(CONFIG_V210_ENCODER)  += v210enc.o
 AVCODECOBJS-$(CONFIG_VP9_DECODER)   += vp9dsp.o
 
diff --git a/tests/checkasm/checkasm.c b/tests/checkasm/checkasm.c
index 9eec41e3c4..bf51e00eab 100644
--- a/tests/checkasm/checkasm.c
+++ b/tests/checkasm/checkasm.c
@@ -136,6 +136,9 @@ static const struct {
 #if CONFIG_UTVIDEO_DECODER
 { "utvideodsp", checkasm_check_utvideodsp },
 #endif
+#if CONFIG_V210_DECODER
+{ "v210dec", checkasm_check_v210dec },
+#endif
 #if CONFIG_V210_ENCODER
 { "v210enc", checkasm_check_v210enc },
 #endif
diff --git a/tests/checkasm/checkasm.h b/tests/checkasm/checkasm.h
index 9e8e879fd3..9b8d2f5419 100644
--- a/tests/checkasm/checkasm.h
+++ b/tests/checkasm/checkasm.h
@@ -69,6 +69,7 @@ void checkasm_check_sbrdsp(void);
 void checkasm_check_synth_filter(void);
 void checkasm_check_sw_rgb(void);
 void checkasm_check_utvideodsp(void);
+void checkasm_check_v210dec(void);
 void checkasm_check_v210enc(void);
 void checkasm_check_vf_hflip(void);
 void checkasm_check_vf_threshold(void);
diff --git a/tests/checkasm/v210dec.c b/tests/checkasm/v210dec.c
new file mode 100644
index 00..7320ed5e37
--- /dev/null
+++ b/tests/checkasm/v210dec.c
@@ -0,0 +1,76 @@
+/*
+ * Copyright (c) 2019 James Darnley
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU 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.
+ */
+
+#include 
+#include "checkasm.h"
+#include "libavcodec/v210dec.h"
+
+static uint32_t get_v210(void)
+{
+uint32_t t0 = rnd() & 0x3ff,
+ t1 = rnd() & 0x3ff,
+ t2 = rnd() & 0x3ff;
+uint32_t value =  t0
+   | (t1 << 10)
+   | (t2 << 20);
+return value;
+}
+
+#define NUM_SAMPLES 2048
+
+static void randomize_buffers(uint32_t *src0, uint32_t *src1, int len)
+{
+for (int i = 0; i < len; i++) {
+uint32_t value = get_v210();
+src0[i] = value;
+src1[i] = value;
+}
+}
+
+void checkasm_check_v210dec(void)
+{
+V210DecContext h;
+
+ff_v210dec_init();
+
+if (check_func(h.unpack_frame, "v210_unpack")) {
+uint32_t src0[NUM_SAMPLES/3];
+uint32_t src1[NUM_SAMPLES/3];
+uint16_t y0[NUM_SAMPLES/2];
+uint16_t y1[NUM_SAMPLES/2];
+uint16_t u0[NUM_SAMPLES/4];
+uint16_t u1[NUM_SAMPLES/4];
+uint16_t v0[NUM_SAMPLES/4];
+uint16_t v1[NUM_SAMPLES/4];
+declare_func(void, const uint32_t *src, uint16_t *y, uint16_t *u, 
uint16_t *v, int width);
+const int pixels = NUM_SAMPLES / 2 / 6 * 6;
+
+randomize_buffers(src0, src1, NUM_SAMPLES/3);
+call_ref(src0, y0, u0, v0, pixels);
+call_new(src1, y1, u1, v1, pixels);
+if (memcmp(src0, src1, NUM_SAMPLES/3 * sizeof src0[0])
+|| memcmp(y0, y1, pixels * sizeof y0[0])
+|| memcmp(u0, u1, pixels/2 * sizeof u0[0])
+|| memcmp(v0, v1, pixels/2 * sizeof v0[0]))
+fail();
+bench_new(src1, y1, u1, v1, pixels);
+}
+report("v210_unpack");
+}
-- 
2.20.1

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


Re: [FFmpeg-devel] question for ff_extract_extradata_bsf

2019-03-06 Thread James Almer
On 3/6/2019 4:04 PM, Yufei He wrote:
> Hi
> 
> I want to use   ff_extract_extradata_bsf to get extradata from a h.264 frame.
> 
> Here is the code.
> 
> AVPacket *avpkt; // there is valid data.
> AVBSFContext *ctx = NULL;
> ret = av_bsf_alloc(_extract_extradata_bsf, );
> ret = ff_extract_extradata_bsf.init(ctx);
> ret = ff_extract_extradata_bsf.filter(ctx, avpkt);
> 
> ff_extract_extradata_bsf.filter failed on calling ff_bsf_get_packet_ref 
> because  ctx->internal->buffer+pkt->data is NULL.
> 
> int ff_bsf_get_packet_ref(AVBSFContext *ctx, AVPacket *pkt)
> {
> AVBSFInternal *in = ctx->internal;
> if (in->eof)
> return AVERROR_EOF;
> if (!ctx->internal->buffer_pkt->data &&
> !ctx->internal->buffer_pkt->side_data_elems)
> return AVERROR(EAGAIN);
> 
> How should ctx->internal->buffer+pkt->data be set?
> 
> Thanks.
> 
> Yufei.

You're not using the bsf API correctly. You're accessing internal
callbacks like init() and filter() directly. Use the public functions
defined in avcodec.h, and look at usage examples like in ffmpeg.c if needed.

Also, any further questions or emails about this should go to the
libav-user list at https://lists.ffmpeg.org/mailman/listinfo/libav-user/
This list is for actual ffmpeg development, not for usage questions.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] question for ff_extract_extradata_bsf

2019-03-06 Thread Yufei He
Hi

I want to use   ff_extract_extradata_bsf to get extradata from a h.264 frame.

Here is the code.

AVPacket *avpkt; // There is valid data.
AVBSFContext *ctx = NULL;
ret = av_bsf_alloc(_extract_extradata_bsf, );
ret = ff_extract_extradata_bsf.init(ctx);
ret = ff_extract_extradata_bsf.filter(ctx, avpkt);

ff_extract_extradata_bsf.filter failed on calling ff_bsf_get_packet_ref because 
 ctx->internal->buffer_pkt->data is NULL.

int ff_bsf_get_packet_ref(AVBSFContext *ctx, AVPacket *pkt)
{
AVBSFInternal *in = ctx->internal;
if (in->eof)
return AVERROR_EOF;
if (!ctx->internal->buffer_pkt->data &&
!ctx->internal->buffer_pkt->side_data_elems)
return AVERROR(EAGAIN);

...
}


How should ctx->internal->buffer+pkt->data be set?

Thanks.

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


Re: [FFmpeg-devel] [PATCH] avcodec/nvenc: Reconfigure resolution on-the-fly

2019-03-06 Thread Oliver Collyer
>> diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
>> index 0ce22ec4fa..7087f82ce1 100644
>> --- a/libavcodec/avcodec.h
>> +++ b/libavcodec/avcodec.h
>> @@ -3357,6 +3357,12 @@ typedef struct AVCodecContext {
>>  * - encoding: unused
>>  */
>> int discard_damaged_percentage;
>> +
>> +/*
>> + * Video encoding only. Sets the maximum picture size for encoders that
>> + * support adjusting the picture size dynamically during encoding.
>> + */
>> + int max_width, max_height;
>> } AVCodecContext;
>> 
> 
> I really don't like introducing public API fields for this. Maybe a
> private nvenc option would be better at this point.
> 

So would this be suitable?

The only thing was that I wasn't sure about exposing these options to ffmpeg 
though, as they're useless to ffmpeg unless ffmpeg were to add features for 
dynamically changing the encoded resolutionI just couldn't figure out how 
you can add a private option that isn't exposed in this way though.

>

diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c
index 304a684e0c..1a1331d468 100644
--- a/libavcodec/nvenc.c
+++ b/libavcodec/nvenc.c
@@ -384,6 +384,7 @@ static int nvenc_check_capabilities(AVCodecContext *avctx)
 #endif
 
 ctx->support_dyn_bitrate = nvenc_check_cap(avctx, 
NV_ENC_CAPS_SUPPORT_DYN_BITRATE_CHANGE);
+ctx->support_dyn_res = nvenc_check_cap(avctx, 
NV_ENC_CAPS_SUPPORT_DYN_RES_CHANGE);
 
 return 0;
 }
@@ -1121,6 +1122,8 @@ static av_cold int nvenc_setup_encoder(AVCodecContext 
*avctx)
 
 ctx->init_encode_params.encodeHeight = avctx->height;
 ctx->init_encode_params.encodeWidth = avctx->width;
+ctx->init_encode_params.maxEncodeHeight = ctx->max_height;
+ctx->init_encode_params.maxEncodeWidth = ctx->max_width;
 
 ctx->init_encode_params.encodeConfig = >encode_config;
 
@@ -1276,8 +1279,8 @@ static av_cold int nvenc_alloc_surface(AVCodecContext 
*avctx, int idx)
 }
 
 allocSurf.version = NV_ENC_CREATE_INPUT_BUFFER_VER;
-allocSurf.width = avctx->width;
-allocSurf.height = avctx->height;
+allocSurf.width = FFMAX(ctx->max_width, avctx->width);
+allocSurf.height = FFMAX(ctx->max_height, avctx->height);
 allocSurf.bufferFmt = ctx->surfaces[idx].format;
 
 nv_status = p_nvenc->nvEncCreateInputBuffer(ctx->nvencoder, 
);
@@ -1926,7 +1929,7 @@ static void reconfig_encoder(AVCodecContext *avctx, const 
AVFrame *frame)
 NV_ENC_RECONFIGURE_PARAMS params = { 0 };
 int needs_reconfig = 0;
 int needs_encode_config = 0;
-int reconfig_bitrate = 0, reconfig_dar = 0;
+int reconfig_bitrate = 0, reconfig_dar = 0, reconfig_res = 0;
 int dw, dh;
 
 params.version = NV_ENC_RECONFIGURE_PARAMS_VER;
@@ -1986,6 +1989,24 @@ static void reconfig_encoder(AVCodecContext *avctx, 
const AVFrame *frame)
 }
 }
 
+if (ctx->support_dyn_res && ctx->init_encode_params.maxEncodeWidth && 
ctx->init_encode_params.maxEncodeHeight) {
+if (params.reInitEncodeParams.encodeWidth != avctx->width || 
params.reInitEncodeParams.encodeHeight != avctx->height) {
+av_log(avctx, AV_LOG_VERBOSE,
+"resolution change: %d x %d -> %d x %d\n",
+params.reInitEncodeParams.encodeWidth,
+params.reInitEncodeParams.encodeHeight,
+(uint32_t)avctx->width,
+(uint32_t)avctx->height);
+
+params.reInitEncodeParams.encodeWidth = avctx->width;
+params.reInitEncodeParams.encodeHeight = avctx->height;
+params.forceIDR = 1;
+
+needs_reconfig = 1;
+reconfig_res = 1;
+}
+}
+
 if (!needs_encode_config)
 params.reInitEncodeParams.encodeConfig = NULL;
 
@@ -2005,6 +2026,10 @@ static void reconfig_encoder(AVCodecContext *avctx, 
const AVFrame *frame)
 ctx->encode_config.rcParams.vbvBufferSize = 
params.reInitEncodeParams.encodeConfig->rcParams.vbvBufferSize;
 }
 
+if (reconfig_res) {
+ctx->init_encode_params.encodeWidth = 
params.reInitEncodeParams.encodeWidth;
+ctx->init_encode_params.encodeHeight = 
params.reInitEncodeParams.encodeHeight;
+}
 }
 }
 }
diff --git a/libavcodec/nvenc.h b/libavcodec/nvenc.h
index ddd6168409..30a3aa6f6f 100644
--- a/libavcodec/nvenc.h
+++ b/libavcodec/nvenc.h
@@ -158,6 +158,7 @@ typedef struct NvencContext
 int first_packet_output;
 
 int support_dyn_bitrate;
+int support_dyn_res;
 
 void *nvencoder;
 
@@ -192,6 +193,8 @@ typedef struct NvencContext
 int coder;
 int b_ref_mode;
 int a53_cc;
+int max_width;
+int max_height;
 } NvencContext;
 
 int ff_nvenc_encode_init(AVCodecContext *avctx);
diff --git a/libavcodec/nvenc_h264.c b/libavcodec/nvenc_h264.c
index a6623f5f35..9c9a0c7b8d 100644
--- a/libavcodec/nvenc_h264.c
+++ b/libavcodec/nvenc_h264.c
@@ -138,6 +138,10 @@ static const AVOption options[] = {
 { 

[FFmpeg-devel] question for ff_extract_extradata_bsf

2019-03-06 Thread Yufei He
Hi

I want to use   ff_extract_extradata_bsf to get extradata from a h.264 frame.

Here is the code.

AVPacket *avpkt; // there is valid data.
AVBSFContext *ctx = NULL;
ret = av_bsf_alloc(_extract_extradata_bsf, );
ret = ff_extract_extradata_bsf.init(ctx);
ret = ff_extract_extradata_bsf.filter(ctx, avpkt);

ff_extract_extradata_bsf.filter failed on calling ff_bsf_get_packet_ref because 
 ctx->internal->buffer+pkt->data is NULL.

int ff_bsf_get_packet_ref(AVBSFContext *ctx, AVPacket *pkt)
{
AVBSFInternal *in = ctx->internal;
if (in->eof)
return AVERROR_EOF;
if (!ctx->internal->buffer_pkt->data &&
!ctx->internal->buffer_pkt->side_data_elems)
return AVERROR(EAGAIN);

How should ctx->internal->buffer+pkt->data be set?

Thanks.

Yufei.



On 03/06/2019 01:09 PM, Lynne wrote:

A lot of files have CRC included.
The CRC only covers 34 bytes at most from the frame but it should still be
enough for some amount of error detection.




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


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


[FFmpeg-devel] [PATCH] mpegaudiodec_template: add ability to check CRC

2019-03-06 Thread Lynne
A lot of files have CRC included.
The CRC only covers 34 bytes at most from the frame but it should still be
enough for some amount of error detection.
>From e1f4410f35d3d7f774a0de59ab72764033d14900 Mon Sep 17 00:00:00 2001
From: Lynne 
Date: Wed, 6 Mar 2019 17:04:04 +
Subject: [PATCH] mpegaudiodec_template: add ability to check CRC

A lot of files have CRC included.
The CRC only covers 34 bytes at most from the frame but it should still be
enough for some amount of error detection.
---
 libavcodec/mpegaudiodec_template.c | 20 +---
 1 file changed, 17 insertions(+), 3 deletions(-)

diff --git a/libavcodec/mpegaudiodec_template.c b/libavcodec/mpegaudiodec_template.c
index 9cce88e263..0881b60bf5 100644
--- a/libavcodec/mpegaudiodec_template.c
+++ b/libavcodec/mpegaudiodec_template.c
@@ -27,6 +27,7 @@
 #include "libavutil/attributes.h"
 #include "libavutil/avassert.h"
 #include "libavutil/channel_layout.h"
+#include "libavutil/crc.h"
 #include "libavutil/float_dsp.h"
 #include "libavutil/libm.h"
 #include "avcodec.h"
@@ -1565,9 +1566,22 @@ static int mp_decode_frame(MPADecodeContext *s, OUT_INT **samples,
 
 init_get_bits(>gb, buf + HEADER_SIZE, (buf_size - HEADER_SIZE) * 8);
 
-/* skip error protection field */
-if (s->error_protection)
-skip_bits(>gb, 16);
+if (s->error_protection) {
+uint16_t crc = get_bits(>gb, 16);
+if (s->err_recognition & AV_EF_CRCCHECK) {
+const int sec_len = s->lsf ? ((s->nb_channels == 1) ? 9  : 17) :
+ ((s->nb_channels == 1) ? 17 : 32);
+const AVCRC *crc_tab = av_crc_get_table(AV_CRC_16_ANSI);
+uint32_t crc_cal = av_crc(crc_tab, UINT16_MAX, [2], 2);
+crc_cal = av_crc(crc_tab, crc_cal, [6], sec_len);
+
+if (av_bswap16(crc) ^ crc_cal) {
+av_log(s->avctx, AV_LOG_ERROR, "CRC mismatch!\n");
+if (s->err_recognition & AV_EF_EXPLODE)
+return AVERROR_INVALIDDATA;
+}
+}
+}
 
 switch(s->layer) {
 case 1:
-- 
2.21.0

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


Re: [FFmpeg-devel] [PATCH 1/2] avcodec/v210dec: move DSP function setting into dedicated function

2019-03-06 Thread James Darnley
On 2019-03-06 10:11, Paul B Mahol wrote:
> On 3/6/19, Carl Eugen Hoyos  wrote:
>> 2019-03-04 23:58 GMT+01:00, James Darnley :
>>> Prepare for checkasm test.
>>> ---
>>>  libavcodec/v210dec.c | 13 +
>>>  libavcodec/v210dec.h |  1 +
>>>  2 files changed, 10 insertions(+), 4 deletions(-)
>>>
>>> diff --git a/libavcodec/v210dec.c b/libavcodec/v210dec.c
>>> index ddc5dbe8be..28cf00d320 100644
>>> --- a/libavcodec/v210dec.c
>>> +++ b/libavcodec/v210dec.c
>>> @@ -50,6 +50,14 @@ static void v210_planar_unpack_c(const uint32_t *src,
>>> uint16_t *y, uint16_t *u,
>>>  }
>>>  }
>>>
>>> +av_cold void ff_v210dec_init(V210DecContext *s)
>>> +{
>>> +s->unpack_frame = v210_planar_unpack_c;
>>
>>> +s->aligned_input = 0;
>>
>> Isn't this an unrelated change or do I misunderstand?
> 
> You misunderstand.

Maybe.

I need to initialize that member before it is used in the x86 function.
I expect valgrind or similar would catch the use.

It doesn't matter for normal use because it will be set correctly based
on the input data alignment for each frame.  Now that you mention it I
realize I forgot to change that to call the new function so I will send
a v2 later.

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


Re: [FFmpeg-devel] [PATCH v2] avformat/mpegts: reduce buffering during initialization

2019-03-06 Thread Andriy Gelman
> Would it be an alternative to add an option that allows to force
> the packet size?

I like the idea. I guess the options are:
1. Set packet size + Use old version (fixed 8192 buffer) to estimate
parameter if not set by user.
2. Set packet size + Use new version (adaptive buffer) to estimate
parameter if not set by user.

Regards,
Andriy


On Wed, 6 Mar 2019 at 02:51, Carl Eugen Hoyos  wrote:

> 2019-03-06 7:01 GMT+01:00, Andriy Gelman :
> > From: Andriy Gelman 
> >
> > Reduces buffering latency with low bitrate streams, where
> > 8192 bytes can mean several seconds.
>
> Would it be an alternative to add an option that allows to force
> the packet size?
>
> Carl Eugen
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] avformat/mpegts.c: reduce buffering during initialization

2019-03-06 Thread Andriy Gelman
Marton, Michael, thanks for your feedback.
I've updated the patch based on your comments.

> I can see that you are increasing linearly, maybe doubling the bufsize
> with each step is better, although in this case it probably does not
> matter too much.
> On the other hand, the maximum 8K seems small enough to allocate it at
the
> start of the function instead of reallocing it with each step.

I've allocated the buffer at the start of the function.

> You seem to be changing the logic:
> Old code: report packet size if candidate score is better than other
> scores.
> New code: report packet size with first best score no matter if the other
> scores are the same.
> Old logic seems less error-prone, so you should determine the winner
based
> on that, and stay in the loop if no winner is found.

I've changed the logic to follow the original code. The only difference is
that I've added a margin such that the winner is larger by
PROBE_PACKET_MARGIN.
The margin is set to zero when the buffer size is 8192 bytes, so that the
results of new and old code will be the same when buffer is filled, or
there is an eof.

> the end condition is not robust
> if you have scores 100 and 101, 101 is better but the difference is too
small
> to stop the loop without risk that the other might be better later

I've added a margin when comparing the scores. I.e.:
if (score > FFMAX(fec_score, dvhs_score) + margin)
return TS_PACKET_SIZE;
Does the use of margin address your comment?

> the use of AVProbeData does not seem to help this code in any way

I've removed AVProbeData and added buffer to stack.

Regards,
Andriy


On Tue, 5 Mar 2019 at 19:25, Michael Niedermayer 
wrote:

> On Mon, Mar 04, 2019 at 10:21:01PM -0500, andriy.gel...@gmail.com wrote:
> > From: Andriy Gelman 
> >
> > Reduces buffering during estimation of mpegts raw_packet_size
> > parameter. Instead of buffering a fixed 8192 bytes, calculate
> > probe scores on a smaller buffer. Increase buffer size until
> > probe score is greater than minimum value.
> > ---
> >  libavformat/mpegts.c | 82 +++-
> >  1 file changed, 59 insertions(+), 23 deletions(-)
> >
> > diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c
> > index b04fd7b4f4..a7b33eae69 100644
> > --- a/libavformat/mpegts.c
> > +++ b/libavformat/mpegts.c
> > @@ -53,6 +53,10 @@
> >  (prev_dividend) = (dividend);
> \
> >  } while (0)
> >
> > +#define MAX_RAW_PACKET_PROBE 8192
> > +#define PROBE_PACKET_STEP 512
> > +#define RAW_PACKET_MIN_SCORE 10
> > +
> >  enum MpegTSFilterType {
> >  MPEGTS_PES,
> >  MPEGTS_SECTION,
> > @@ -591,28 +595,64 @@ static int analyze(const uint8_t *buf, int size,
> int packet_size,
> >  return best_score - FFMAX(stat_all - 10*best_score, 0)/10;
> >  }
> >
> > -/* autodetect fec presence. Must have at least 1024 bytes  */
> > -static int get_packet_size(const uint8_t *buf, int size)
> > +/* autodetect fec presence */
> > +static int get_packet_size(AVIOContext* pb)
> >  {
> >  int score, fec_score, dvhs_score;
> > +int pd_packet_size = TS_PACKET_SIZE;
> > +int best_score = 0;
> > +int ret;
> >
> > -if (size < (TS_FEC_PACKET_SIZE * 5 + 1))
> > -return AVERROR_INVALIDDATA;
> > +AVProbeData pd = { 0 };
> > +while (best_score < RAW_PACKET_MIN_SCORE &&
> > +pd.buf_size + PROBE_PACKET_STEP <= MAX_RAW_PACKET_PROBE) {
>
> the end condition is not robust
> if you have scores 100 and 101, 101 is better but the difference is too
> small
> to stop the loop without risk that the other moght be better later
>
> the use of AVProbeData does not seem to help this code in any way
>
>
> > +
> > +/*create extra space for next packet*/
> > +uint8_t *new_buf = av_realloc(pd.buf, pd.buf_size +
> PROBE_PACKET_STEP);
>
> the previous code needed no dynamic allocation. Changing that is not needed
> and would e a seperate issue and require an explanation why.
>
> overall this patch looks like it changes alot more than whats needed
> to run the code with less data in an initial iteration
>
> thx
>
> [...]
> --
> Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
>
> No snowflake in an avalanche ever feels responsible. -- Voltaire
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] avcodec/nvenc: Reconfigure resolution on-the-fly

2019-03-06 Thread Oliver Collyer
>> diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
>> index 0ce22ec4fa..7087f82ce1 100644
>> --- a/libavcodec/avcodec.h
>> +++ b/libavcodec/avcodec.h
>> @@ -3357,6 +3357,12 @@ typedef struct AVCodecContext {
>>  * - encoding: unused
>>  */
>> int discard_damaged_percentage;
>> +
>> +/*
>> + * Video encoding only. Sets the maximum picture size for encoders that
>> + * support adjusting the picture size dynamically during encoding.
>> + */
>> + int max_width, max_height;
>> } AVCodecContext;
>> 
> 
> I really don't like introducing public API fields for this. Maybe a
> private nvenc option would be better at this point.
> 

Yeah, I just thought if you wanted to use the fields similarly for other 
encoders in future?

Happy to change it though.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] avcodec/nvenc: Reconfigure resolution on-the-fly

2019-03-06 Thread Hendrik Leppkes
On Wed, Mar 6, 2019 at 3:57 PM Oliver Collyer  wrote:
>
> diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
> index 0ce22ec4fa..7087f82ce1 100644
> --- a/libavcodec/avcodec.h
> +++ b/libavcodec/avcodec.h
> @@ -3357,6 +3357,12 @@ typedef struct AVCodecContext {
>   * - encoding: unused
>   */
>  int discard_damaged_percentage;
> +
> +/*
> + * Video encoding only. Sets the maximum picture size for encoders that
> + * support adjusting the picture size dynamically during encoding.
> + */
> + int max_width, max_height;
>  } AVCodecContext;
>

I really don't like introducing public API fields for this. Maybe a
private nvenc option would be better at this point.

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


[FFmpeg-devel] [PATCH] avformat/mpegtsenc:

2019-03-06 Thread Oliver Collyer
Hi

I needed to be able to use the write_data_type callback when reading data from 
the mpegts muxer, to make my application aware of key frames in the data so I 
added support. I used the matroska implementation as a reference.

If this is accepted, I will format this as a proper patch after feedback.

Regards

Oliver

diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c
index fc0ea225c6..e5d1a64b4c 100644
--- a/libavformat/mpegtsenc.c
+++ b/libavformat/mpegtsenc.c
@@ -1815,6 +1815,12 @@ static int mpegts_write_packet(AVFormatContext *s, 
AVPacket *pkt)
 mpegts_write_flush(s);
 return 1;
 } else {
+if (s->pb && s->pb->write_data_type) {
+AVStream *st = s->streams[pkt->stream_index];
+avio_write_marker(s->pb,
+av_rescale_q(pkt->dts, st->time_base, AV_TIME_BASE_Q),
+(pkt->flags & AV_PKT_FLAG_KEY) && st->codecpar->codec_type == 
AVMEDIA_TYPE_VIDEO ? AVIO_DATA_MARKER_SYNC_POINT : 
AVIO_DATA_MARKER_BOUNDARY_POINT);
+}
 return mpegts_write_packet_internal(s, pkt);
 }
 }

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


[FFmpeg-devel] [PATCH] avcodec/nvenc: Reconfigure resolution on-the-fly

2019-03-06 Thread Oliver Collyer
Hi

I needed the dynamic resolution changing feature of NVENC to be accessible 
through the ffmpeg libraries for a hobby project, so I added support and here 
is a patch.

I will format this as a proper patch after any changes necessary following 
feedback.

To use this feature you would need to:

1. Specify max_width and max_height before opening the encoder
2. Change the encoder context width/height during encoding

Note that it is the caller's responsibility to scale the input frames to match 
the new encoder size after changing it! In my test I just use sws_scale where 
needed.

Here is a link to a file that switches resolution a few times between 1920x1080 
and 1280x720, that was generated using this patch. This plays correctly in VLC.

https://www.dropbox.com/s/rvt94ai3jx5lbi9/test_switching_2.ts?dl=0 


Regards

Oliver


diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 0ce22ec4fa..7087f82ce1 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -3357,6 +3357,12 @@ typedef struct AVCodecContext {
  * - encoding: unused
  */
 int discard_damaged_percentage;
+
+/*
+ * Video encoding only. Sets the maximum picture size for encoders that
+ * support adjusting the picture size dynamically during encoding.
+ */
+ int max_width, max_height;
 } AVCodecContext;
 
 #if FF_API_CODEC_GET_SET
diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c
index 304a684e0c..414707dcfd 100644
--- a/libavcodec/nvenc.c
+++ b/libavcodec/nvenc.c
@@ -384,6 +384,7 @@ static int nvenc_check_capabilities(AVCodecContext *avctx)
 #endif
 
 ctx->support_dyn_bitrate = nvenc_check_cap(avctx, 
NV_ENC_CAPS_SUPPORT_DYN_BITRATE_CHANGE);
+ctx->support_dyn_res = nvenc_check_cap(avctx, 
NV_ENC_CAPS_SUPPORT_DYN_RES_CHANGE);
 
 return 0;
 }
@@ -1121,6 +1122,8 @@ static av_cold int nvenc_setup_encoder(AVCodecContext 
*avctx)
 
 ctx->init_encode_params.encodeHeight = avctx->height;
 ctx->init_encode_params.encodeWidth = avctx->width;
+ctx->init_encode_params.maxEncodeHeight = avctx->max_height;
+ctx->init_encode_params.maxEncodeWidth = avctx->max_width;
 
 ctx->init_encode_params.encodeConfig = >encode_config;
 
@@ -1276,8 +1279,8 @@ static av_cold int nvenc_alloc_surface(AVCodecContext 
*avctx, int idx)
 }
 
 allocSurf.version = NV_ENC_CREATE_INPUT_BUFFER_VER;
-allocSurf.width = avctx->width;
-allocSurf.height = avctx->height;
+allocSurf.width = FFMAX(avctx->max_width, avctx->width);
+allocSurf.height = FFMAX(avctx->max_height, avctx->height);
 allocSurf.bufferFmt = ctx->surfaces[idx].format;
 
 nv_status = p_nvenc->nvEncCreateInputBuffer(ctx->nvencoder, 
);
@@ -1926,7 +1929,7 @@ static void reconfig_encoder(AVCodecContext *avctx, const 
AVFrame *frame)
 NV_ENC_RECONFIGURE_PARAMS params = { 0 };
 int needs_reconfig = 0;
 int needs_encode_config = 0;
-int reconfig_bitrate = 0, reconfig_dar = 0;
+int reconfig_bitrate = 0, reconfig_dar = 0, reconfig_res = 0;
 int dw, dh;
 
 params.version = NV_ENC_RECONFIGURE_PARAMS_VER;
@@ -1986,6 +1989,24 @@ static void reconfig_encoder(AVCodecContext *avctx, 
const AVFrame *frame)
 }
 }
 
+if (ctx->support_dyn_res && ctx->init_encode_params.maxEncodeWidth && 
ctx->init_encode_params.maxEncodeHeight) {
+if (params.reInitEncodeParams.encodeWidth != avctx->width || 
params.reInitEncodeParams.encodeHeight != avctx->height) {
+av_log(avctx, AV_LOG_VERBOSE,
+"resolution change: %d x %d -> %d x %d\n",
+params.reInitEncodeParams.encodeWidth,
+params.reInitEncodeParams.encodeHeight,
+(uint32_t)avctx->width,
+(uint32_t)avctx->height);
+
+params.reInitEncodeParams.encodeWidth = avctx->width;
+params.reInitEncodeParams.encodeHeight = avctx->height;
+params.forceIDR = 1;
+
+needs_reconfig = 1;
+reconfig_res = 1;
+}
+}
+
 if (!needs_encode_config)
 params.reInitEncodeParams.encodeConfig = NULL;
 
@@ -2005,6 +2026,10 @@ static void reconfig_encoder(AVCodecContext *avctx, 
const AVFrame *frame)
 ctx->encode_config.rcParams.vbvBufferSize = 
params.reInitEncodeParams.encodeConfig->rcParams.vbvBufferSize;
 }
 
+if (reconfig_res) {
+ctx->init_encode_params.encodeWidth = 
params.reInitEncodeParams.encodeWidth;
+ctx->init_encode_params.encodeHeight = 
params.reInitEncodeParams.encodeHeight;
+}
 }
 }
 }
diff --git a/libavcodec/nvenc.h b/libavcodec/nvenc.h
index ddd6168409..f3b959b31a 100644
--- a/libavcodec/nvenc.h
+++ b/libavcodec/nvenc.h
@@ -158,6 +158,7 @@ typedef struct NvencContext
 int first_packet_output;
 
 int support_dyn_bitrate;
+int support_dyn_res;
 
 void *nvencoder;
 
diff 

Re: [FFmpeg-devel] [PATCH]lavf/mxfdec: Allow MXF parser to identify the Canon XF-HEVC codec/format for video essence

2019-03-06 Thread Tomas Härdin
ons 2019-03-06 klockan 15:05 +0100 skrev Carl Eugen Hoyos:
> > 2019-03-06 14:38 GMT+01:00, Tomas Härdin :
> 
> > I have generated new samples, sourced with test pattern,
> > some as short as 1 second, about 1.2 megabytes per file.
> > If real-life clips are required, or if the expectation is for me
> > to perform the FATE tests, let me know.
> 
> Could this get committed without fate test first, and we can
> discuss later if they are really required?

Sure. We can wait a day or two for more feedback then push the first
patch. Maybe Baptiste wants to chime in

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


Re: [FFmpeg-devel] [PATCH]lavf/mxfdec: Allow MXF parser to identify the Canon XF-HEVC codec/format for video essence

2019-03-06 Thread Carl Eugen Hoyos
2019-03-06 14:38 GMT+01:00, Tomas Härdin :

> I have generated new samples, sourced with test pattern,
> some as short as 1 second, about 1.2 megabytes per file.
> If real-life clips are required, or if the expectation is for me
> to perform the FATE tests, let me know.

Could this get committed without fate test first, and we can
discuss later if they are really required?

(Assuming there is no "parsing" involved, just a new UL which
reminds me you could remove the word parser from the
commit message.)

Thank you, Carl Eugen
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] apedec: add ability to check CRC

2019-03-06 Thread Lynne
6 Mar 2019, 11:22 by d...@lynne.ee:

> The CRC flag is only signalled once every few minutes but CRC is still
> always present so the patch uses the file version instead.
> CRC on 24-bit files wants non-padded samples so skip such files.
> Some corrupt samples may have been output before the final check
> depending on the -max_samples setting.
>
v2 attached
>From 68c25bb026761eacda3c276148e2beb34e8929fd Mon Sep 17 00:00:00 2001
From: Lynne 
Date: Wed, 6 Mar 2019 11:01:01 +
Subject: [PATCH v2] apedec: add ability to check CRC

The CRC flag is only signalled once every few minutes but CRC is still
always present so the patch uses the file version instead.
CRC on 24-bit files wants non-padded samples so skip such files.
Some corrupt samples may have been output before the final check
depending on the -max_samples setting.
---
 libavcodec/apedec.c | 26 +-
 1 file changed, 25 insertions(+), 1 deletion(-)

diff --git a/libavcodec/apedec.c b/libavcodec/apedec.c
index 15eb416ba4..a20d884606 100644
--- a/libavcodec/apedec.c
+++ b/libavcodec/apedec.c
@@ -24,6 +24,7 @@
 
 #include "libavutil/avassert.h"
 #include "libavutil/channel_layout.h"
+#include "libavutil/crc.h"
 #include "libavutil/opt.h"
 #include "lossless_audiodsp.h"
 #include "avcodec.h"
@@ -147,7 +148,8 @@ typedef struct APEContext {
 int fset;///< which filter set to use (calculated from compression level)
 int flags;   ///< global decoder flags
 
-uint32_t CRC;///< frame CRC
+uint32_t CRC;///< signalled frame CRC
+uint32_t CRC_state;  ///< accumulated CRC
 int frameflags;  ///< frame flags
 APEPredictor predictor;  ///< predictor used for final reconstruction
 
@@ -730,6 +732,7 @@ static int init_entropy_decoder(APEContext *ctx)
 
 /* Read the frame flags if they exist */
 ctx->frameflags = 0;
+ctx->CRC_state = UINT32_MAX;
 if ((ctx->fileversion > 3820) && (ctx->CRC & 0x8000)) {
 ctx->CRC &= ~0x8000;
 
@@ -1548,6 +1551,27 @@ static int ape_decode_frame(AVCodecContext *avctx, void *data,
 
 s->samples -= blockstodecode;
 
+if ((avctx->err_recognition & AV_EF_CRCCHECK) &&
+(s->fileversion >= 3900) && (s->bps < 24)) {
+uint32_t crc = s->CRC_state;
+const AVCRC *crc_tab = av_crc_get_table(AV_CRC_32_IEEE_LE);
+for (i = 0; i < blockstodecode; i++) {
+for (ch = 0; ch < s->channels; ch++) {
+uint8_t *smp = frame->data[ch] + (i*(s->bps >> 3));
+crc = av_crc(crc_tab, crc, smp, s->bps >> 3);
+}
+}
+
+if (!s->samples && ((~crc >> 1) ^ s->CRC)) {
+av_log(avctx, AV_LOG_ERROR, "CRC mismatch! Previously decoded "
+   "frames may have been affected as well.\n");
+if (avctx->err_recognition & AV_EF_EXPLODE)
+return AVERROR_INVALIDDATA;
+}
+
+s->CRC_state = crc;
+}
+
 *got_frame_ptr = 1;
 
 return !s->samples ? avpkt->size : 0;
-- 
2.21.0

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


Re: [FFmpeg-devel] [PATCH 2/2] avcodec/libdav1d: use a custom picture allocator

2019-03-06 Thread James Almer
On 3/6/2019 10:33 AM, Carl Eugen Hoyos wrote:
> 2019-03-06 14:22 GMT+01:00, James Almer :
>> On 3/6/2019 5:06 AM, Carl Eugen Hoyos wrote:
>>> 2019-03-04 22:06 GMT+01:00, James Almer :
>>>
 +static const enum AVPixelFormat pix_fmt[][3] = {
 +[DAV1D_PIXEL_LAYOUT_I400] = { AV_PIX_FMT_GRAY8,   AV_PIX_FMT_GRAY10,
 AV_PIX_FMT_GRAY12 },
 +[DAV1D_PIXEL_LAYOUT_I420] = { AV_PIX_FMT_YUV420P,
 AV_PIX_FMT_YUV420P10,
 AV_PIX_FMT_YUV420P12 },
 +[DAV1D_PIXEL_LAYOUT_I422] = { AV_PIX_FMT_YUV422P,
 AV_PIX_FMT_YUV422P10,
 AV_PIX_FMT_YUV422P12 },
 +[DAV1D_PIXEL_LAYOUT_I444] = { AV_PIX_FMT_YUV444P,
 AV_PIX_FMT_YUV444P10,
 AV_PIX_FMT_YUV444P12 },
 +};
>>>
>>> Looks like a separate change.
>>>
>>> And please use the ERROR defines.
>>>
>>> Carl Eugen
>>
>> You want me to move this array up in the file in a separate commit?
> 
> No, I just wanted to carefully remind you that smaller commits
> do have advantages.
> But this is clearly your code.
> 
> Sorry for the noise, Carl Eugen

No, i can do it. Just wanted to make sure you weren't mistakenly seeing
some change to the array which would definitely require a separate commit.
Changed locally.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] apedec: add ability to check CRC

2019-03-06 Thread Hendrik Leppkes
On Wed, Mar 6, 2019 at 2:18 PM Carl Eugen Hoyos  wrote:
>
> 2019-03-06 12:22 GMT+01:00, Lynne :
> > The CRC flag is only signalled once every few minutes but CRC is still
> > always present so the patch uses the file version instead.
> > CRC on 24-bit files wants non-padded samples so skip such files.
> > Some corrupt samples may have been output before the final check
> > depending on the -max_samples setting.
>
> Imo, you should only return an error for some non-default
> strict value (it should be possible for the user to show the
> issue but continue to decode).
>

strict is the wrong value to check here. It could use err_recognition
& AV_EF_EXPLODE and only print otherwise.

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


Re: [FFmpeg-devel] [PATCH 2/2] avcodec/libdav1d: use a custom picture allocator

2019-03-06 Thread Carl Eugen Hoyos
2019-03-06 14:22 GMT+01:00, James Almer :
> On 3/6/2019 5:06 AM, Carl Eugen Hoyos wrote:
>> 2019-03-04 22:06 GMT+01:00, James Almer :
>>
>>> +static const enum AVPixelFormat pix_fmt[][3] = {
>>> +[DAV1D_PIXEL_LAYOUT_I400] = { AV_PIX_FMT_GRAY8,   AV_PIX_FMT_GRAY10,
>>> AV_PIX_FMT_GRAY12 },
>>> +[DAV1D_PIXEL_LAYOUT_I420] = { AV_PIX_FMT_YUV420P,
>>> AV_PIX_FMT_YUV420P10,
>>> AV_PIX_FMT_YUV420P12 },
>>> +[DAV1D_PIXEL_LAYOUT_I422] = { AV_PIX_FMT_YUV422P,
>>> AV_PIX_FMT_YUV422P10,
>>> AV_PIX_FMT_YUV422P12 },
>>> +[DAV1D_PIXEL_LAYOUT_I444] = { AV_PIX_FMT_YUV444P,
>>> AV_PIX_FMT_YUV444P10,
>>> AV_PIX_FMT_YUV444P12 },
>>> +};
>>
>> Looks like a separate change.
>>
>> And please use the ERROR defines.
>>
>> Carl Eugen
>
> You want me to move this array up in the file in a separate commit?

No, I just wanted to carefully remind you that smaller commits
do have advantages.
But this is clearly your code.

Sorry for the noise, Carl Eugen
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] apedec: add ability to check CRC

2019-03-06 Thread James Almer
On 3/6/2019 8:22 AM, Lynne wrote:
> The CRC flag is only signalled once every few minutes but CRC is still
> always present so the patch uses the file version instead.
> CRC on 24-bit files wants non-padded samples so skip such files.
> Some corrupt samples may have been output before the final check
> depending on the -max_samples setting.
> 
> 
> 0001-apedec-add-ability-to-check-CRC.patch
> 
> From ad5773274448c209371dc8c70b4b21f39f968308 Mon Sep 17 00:00:00 2001
> From: Lynne 
> Date: Wed, 6 Mar 2019 11:01:01 +
> Subject: [PATCH] apedec: add ability to check CRC
> 
> The CRC flag is only signalled once every few minutes but CRC is still
> always present so the patch uses the file version instead.
> CRC on 24-bit files wants non-padded samples so skip such files.
> Some corrupt samples may have been output before the final check
> depending on the -max_samples setting.
> ---
>  libavcodec/apedec.c | 25 -
>  1 file changed, 24 insertions(+), 1 deletion(-)
> 
> diff --git a/libavcodec/apedec.c b/libavcodec/apedec.c
> index 15eb416ba4..3208275f6e 100644
> --- a/libavcodec/apedec.c
> +++ b/libavcodec/apedec.c
> @@ -24,6 +24,7 @@
>  
>  #include "libavutil/avassert.h"
>  #include "libavutil/channel_layout.h"
> +#include "libavutil/crc.h"
>  #include "libavutil/opt.h"
>  #include "lossless_audiodsp.h"
>  #include "avcodec.h"
> @@ -147,7 +148,8 @@ typedef struct APEContext {
>  int fset;///< which filter set to use 
> (calculated from compression level)
>  int flags;   ///< global decoder flags
>  
> -uint32_t CRC;///< frame CRC
> +uint32_t CRC;///< signalled frame CRC
> +uint32_t CRC_state;  ///< accumulated CRC
>  int frameflags;  ///< frame flags
>  APEPredictor predictor;  ///< predictor used for final 
> reconstruction
>  
> @@ -730,6 +732,7 @@ static int init_entropy_decoder(APEContext *ctx)
>  
>  /* Read the frame flags if they exist */
>  ctx->frameflags = 0;
> +ctx->CRC_state = ~0U;

nit: UINT32_MAX.

>  if ((ctx->fileversion > 3820) && (ctx->CRC & 0x8000)) {
>  ctx->CRC &= ~0x8000;
>  
> @@ -1548,6 +1551,26 @@ static int ape_decode_frame(AVCodecContext *avctx, 
> void *data,
>  
>  s->samples -= blockstodecode;
>  
> +if ((avctx->err_recognition & (AV_EF_CRCCHECK | AV_EF_COMPLIANT)) &&
> +(s->fileversion >= 3900) && (s->bps < 24)) {
> +uint32_t crc = s->CRC_state;
> +const AVCRC *crc_tab = av_crc_get_table(AV_CRC_32_IEEE_LE);
> +for (i = 0; i < blockstodecode; i++) {
> +for (ch = 0; ch < s->channels; ch++) {
> +uint8_t *smp = frame->data[ch] + (i*(s->bps >> 3));
> +crc = av_crc(crc_tab, crc, smp, s->bps >> 3);
> +}
> +}
> +
> +if (!s->samples && ((~crc >> 1) ^ s->CRC)) {
> +av_log(avctx, AV_LOG_ERROR, "CRC mismatch! Previously decoded "
> +   "frames may have been affected as well.\n");
> +return AVERROR_INVALIDDATA;

Abort with an error only if (avctx->err_recognition & AV_EF_EXPLODE) is
true.

> +}
> +
> +s->CRC_state = crc;
> +}
> +
>  *got_frame_ptr = 1;
>  
>  return !s->samples ? avpkt->size : 0;
> -- 2.21.0
> 
> 
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 

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


Re: [FFmpeg-devel] [PATCH] libdav1d: Add support for reading hdr10 metadata

2019-03-06 Thread James Almer
On 3/6/2019 5:07 AM, Carl Eugen Hoyos wrote:
> 2019-03-05 19:26 GMT+01:00, James Almer :
>> On 3/5/2019 3:19 PM, Vittorio Giovara wrote:
> 
>>> +if (p->mastering_display) {
>>> +AVMasteringDisplayMetadata *mastering =
>>> av_mastering_display_metadata_create_side_data(frame);
>>> +if (!mastering)
>>> +return AVERROR(ENOMEM);
>>> +
>>> +for (i = 0; i < 3; i++) {
>>
>> for (int i = 0,...)
> 
> Being allowed to use doesn't mean it has to be used, no?
> There also is a smaller scope...
> 
> Carl Eugen

There's no smaller scope than directly declaring it in the for() line.
But he can add it right below the AVMasteringDisplayMetadata declaration
if that's preferred. If just don't see why adding an extra line to the
file would be preferred in this specific case to begin with.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 2/2] avcodec/libdav1d: use a custom picture allocator

2019-03-06 Thread James Almer
On 3/6/2019 5:06 AM, Carl Eugen Hoyos wrote:
> 2019-03-04 22:06 GMT+01:00, James Almer :
> 
>> +static const enum AVPixelFormat pix_fmt[][3] = {
>> +[DAV1D_PIXEL_LAYOUT_I400] = { AV_PIX_FMT_GRAY8,   AV_PIX_FMT_GRAY10,
>> AV_PIX_FMT_GRAY12 },
>> +[DAV1D_PIXEL_LAYOUT_I420] = { AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUV420P10,
>> AV_PIX_FMT_YUV420P12 },
>> +[DAV1D_PIXEL_LAYOUT_I422] = { AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUV422P10,
>> AV_PIX_FMT_YUV422P12 },
>> +[DAV1D_PIXEL_LAYOUT_I444] = { AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUV444P10,
>> AV_PIX_FMT_YUV444P12 },
>> +};
> 
> Looks like a separate change.
> 
> And please use the ERROR defines.
> 
> Carl Eugen

You want me to move this array up in the file in a separate commit?
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] apedec: add ability to check CRC

2019-03-06 Thread Carl Eugen Hoyos
2019-03-06 12:22 GMT+01:00, Lynne :
> The CRC flag is only signalled once every few minutes but CRC is still
> always present so the patch uses the file version instead.
> CRC on 24-bit files wants non-padded samples so skip such files.
> Some corrupt samples may have been output before the final check
> depending on the -max_samples setting.

Imo, you should only return an error for some non-default
strict value (it should be possible for the user to show the
issue but continue to decode).

Carl Eugen
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 3/4] lavfi/nlmeans: Checking number precision when computing integral images

2019-03-06 Thread Carl Eugen Hoyos
2019-03-06 12:31 GMT+01:00, myp...@gmail.com :
> On Wed, Mar 6, 2019 at 3:55 PM Carl Eugen Hoyos  wrote:
>>
>> 2019-03-06 4:18 GMT+01:00, Jun Zhao :

>> > +// accumulation of 8-bits uint_8 (uint8_t *src) into 32-bits
>> > (uint32_t *ii)
>> > +// data type, it will have a risk of an integral value becoming
>> > larger than
>> > +// the 32-bits integer capacity and resulting in an integer
>> > overflow.
>> > +if ((w * h * UINT8_MAX) > UINT32_MAX)
>>
>> I don't think UINT8_MAX increases readability and I suspect
>> this should contain "UINT32_MAX / (w*h)" or similar on
>> one side.
>>
> You means like: UINT32_MAX/w < (UINT8_MAX * h) ?

Actually: (UINT32_MAX / w < 255 * h)
(But that may only be me)

Carl Eugen
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] avcodec/proresenc_aw : improve speed by replacing PutBitContext for codeword encoding

2019-03-06 Thread Martin Vignali
> Not sure if this justifies not adding the new code to PutBitContext: it
> doesn't
> have to work for all situations, only for the encoder that initially uses
> it.
>
>
Like the current patch, works on big and little endian,  i will try to
rewrite this patch using a start of a new PutbitContext64.

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


Re: [FFmpeg-devel] [PATCH 3/4] lavfi/nlmeans: Checking number precision when computing integral images

2019-03-06 Thread myp...@gmail.com
On Wed, Mar 6, 2019 at 3:55 PM Carl Eugen Hoyos  wrote:
>
> 2019-03-06 4:18 GMT+01:00, Jun Zhao :
> > From: Jun Zhao 
> >
> > accumulation of 8-bits uint_8 (uint8_t *src) into 32-bits (uint32_t *ii)
> > data type, it will have a risk of an integral value becoming larger than
> > the 32-bits integer capacity and resulting in an integer overflow. For
> > this risk, add a checking with warning message.
> >
> > Signed-off-by: Jun Zhao 
> > ---
> >  libavfilter/vf_nlmeans.c |7 +++
> >  1 files changed, 7 insertions(+), 0 deletions(-)
> >
> > diff --git a/libavfilter/vf_nlmeans.c b/libavfilter/vf_nlmeans.c
> > index dcb5a03..31c8304 100644
> > --- a/libavfilter/vf_nlmeans.c
> > +++ b/libavfilter/vf_nlmeans.c
> > @@ -236,6 +236,13 @@ static void compute_ssd_integral_image(const
> > NLMeansDSPContext *dsp,
> >  // adjusted end x position of the safe area after width of the safe
> > area gets aligned
> >  const int endx_safe = startx_safe + safe_pw;
> >
> > +// accumulation of 8-bits uint_8 (uint8_t *src) into 32-bits (uint32_t
> > *ii)
> > +// data type, it will have a risk of an integral value becoming larger
> > than
> > +// the 32-bits integer capacity and resulting in an integer overflow.
> > +if ((w * h * UINT8_MAX) > UINT32_MAX)
>
> I don't think UINT8_MAX increases readability and I suspect
> this should contain "UINT32_MAX / (w*h)" or similar on
> one side.
>
You means like: UINT32_MAX/w < (UINT8_MAX * h) ?
> > +av_log(NULL, AV_LOG_WARNING,
> > +   "image (%d x %d) integral value maybe overflow.\n", w ,h);
>
> may overflow?
Will update the warning message as the suggestion.Tks
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH] apedec: add ability to check CRC

2019-03-06 Thread Lynne
The CRC flag is only signalled once every few minutes but CRC is still
always present so the patch uses the file version instead.
CRC on 24-bit files wants non-padded samples so skip such files.
Some corrupt samples may have been output before the final check
depending on the -max_samples setting.
>From ad5773274448c209371dc8c70b4b21f39f968308 Mon Sep 17 00:00:00 2001
From: Lynne 
Date: Wed, 6 Mar 2019 11:01:01 +
Subject: [PATCH] apedec: add ability to check CRC

The CRC flag is only signalled once every few minutes but CRC is still
always present so the patch uses the file version instead.
CRC on 24-bit files wants non-padded samples so skip such files.
Some corrupt samples may have been output before the final check
depending on the -max_samples setting.
---
 libavcodec/apedec.c | 25 -
 1 file changed, 24 insertions(+), 1 deletion(-)

diff --git a/libavcodec/apedec.c b/libavcodec/apedec.c
index 15eb416ba4..3208275f6e 100644
--- a/libavcodec/apedec.c
+++ b/libavcodec/apedec.c
@@ -24,6 +24,7 @@
 
 #include "libavutil/avassert.h"
 #include "libavutil/channel_layout.h"
+#include "libavutil/crc.h"
 #include "libavutil/opt.h"
 #include "lossless_audiodsp.h"
 #include "avcodec.h"
@@ -147,7 +148,8 @@ typedef struct APEContext {
 int fset;///< which filter set to use (calculated from compression level)
 int flags;   ///< global decoder flags
 
-uint32_t CRC;///< frame CRC
+uint32_t CRC;///< signalled frame CRC
+uint32_t CRC_state;  ///< accumulated CRC
 int frameflags;  ///< frame flags
 APEPredictor predictor;  ///< predictor used for final reconstruction
 
@@ -730,6 +732,7 @@ static int init_entropy_decoder(APEContext *ctx)
 
 /* Read the frame flags if they exist */
 ctx->frameflags = 0;
+ctx->CRC_state = ~0U;
 if ((ctx->fileversion > 3820) && (ctx->CRC & 0x8000)) {
 ctx->CRC &= ~0x8000;
 
@@ -1548,6 +1551,26 @@ static int ape_decode_frame(AVCodecContext *avctx, void *data,
 
 s->samples -= blockstodecode;
 
+if ((avctx->err_recognition & (AV_EF_CRCCHECK | AV_EF_COMPLIANT)) &&
+(s->fileversion >= 3900) && (s->bps < 24)) {
+uint32_t crc = s->CRC_state;
+const AVCRC *crc_tab = av_crc_get_table(AV_CRC_32_IEEE_LE);
+for (i = 0; i < blockstodecode; i++) {
+for (ch = 0; ch < s->channels; ch++) {
+uint8_t *smp = frame->data[ch] + (i*(s->bps >> 3));
+crc = av_crc(crc_tab, crc, smp, s->bps >> 3);
+}
+}
+
+if (!s->samples && ((~crc >> 1) ^ s->CRC)) {
+av_log(avctx, AV_LOG_ERROR, "CRC mismatch! Previously decoded "
+   "frames may have been affected as well.\n");
+return AVERROR_INVALIDDATA;
+}
+
+s->CRC_state = crc;
+}
+
 *got_frame_ptr = 1;
 
 return !s->samples ? avpkt->size : 0;
-- 
2.21.0

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


Re: [FFmpeg-devel] [PATCH] avcodec/scpr: Fix use of uninitialized variable

2019-03-06 Thread Michael Niedermayer
On Thu, Feb 28, 2019 at 12:49:00AM +0100, Michael Niedermayer wrote:
> Fixes: Undefined shift
> Fixes: 
> 12911/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_SCPR_fuzzer-5677102915911680
> 
> Found-by: continuous fuzzing process 
> https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> Signed-off-by: Michael Niedermayer 
> ---
>  libavcodec/scpr.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

will apply

[...]
-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

He who knows, does not speak. He who speaks, does not know. -- Lao Tsu


signature.asc
Description: PGP signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH] avformat/mov: fix hang while seek on a kind of fragmented mp4.

2019-03-06 Thread Charles Liu
1. organize fragmented information according to the tracks.
2. do NOT skip the last boxes of fragmented info.

ticket #7572

To reproduce #7572, need to revert commit 
aa25198f1b925a464bdfa83a98476f08d26c9209 first. That commit works for ticket 
7572 luckily. However, #7572 has a deeper reason. Mov demuxer consider that 
fragmented index is completed if a ‘sidx’ point to the end of the file. But 
there may be other ‘sidx’ for other tracks. If we skip the tail from there, we 
will missing the last ‘sidx’ and ‘moof’. Then AV_NOPTS_VALUE occurs.

Signed-off-by: Charles Liu 
---
 libavformat/isom.h |  10 +-
 libavformat/mov.c  | 378 +
 2 files changed, 185 insertions(+), 203 deletions(-)

diff --git a/libavformat/isom.h b/libavformat/isom.h
index 69452cae8e..eea8fa4e8f 100644
--- a/libavformat/isom.h
+++ b/libavformat/isom.h
@@ -125,7 +125,7 @@ typedef struct MOVEncryptionIndex {
 } MOVEncryptionIndex;
 
 typedef struct MOVFragmentStreamInfo {
-int id;
+unsigned stsd_id;
 int64_t sidx_pts;
 int64_t first_tfra_pts;
 int64_t tfdt_dts;
@@ -136,14 +136,13 @@ typedef struct MOVFragmentStreamInfo {
 typedef struct MOVFragmentIndexItem {
 int64_t moof_offset;
 int headers_read;
-int current;
-int nb_stream_info;
-MOVFragmentStreamInfo * stream_info;
+MOVFragmentStreamInfo stream_info;
 } MOVFragmentIndexItem;
 
 typedef struct MOVFragmentIndex {
 int allocated_size;
 int complete;
+int id;  // track id
 int current;
 int nb_items;
 MOVFragmentIndexItem * item;
@@ -274,7 +273,8 @@ typedef struct MOVContext {
 int moov_retry;
 int use_mfra_for;
 int has_looked_for_mfra;
-MOVFragmentIndex frag_index;
+unsigned nb_frag_indices;
+MOVFragmentIndex *frag_indices;
 int atom_depth;
 unsigned int aax_mode;  ///< 'aax' file has been detected
 uint8_t file_key[20];
diff --git a/libavformat/mov.c b/libavformat/mov.c
index a7d444b0ee..b150710a40 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -1153,59 +1153,29 @@ static int mov_read_moov(MOVContext *c, AVIOContext 
*pb, MOVAtom atom)
 return 0; /* now go for mdat */
 }
 
-static MOVFragmentStreamInfo * get_frag_stream_info(
-MOVFragmentIndex *frag_index,
-int index,
-int id)
+static MOVFragmentIndex *mov_find_frag_index(MOVFragmentIndex *frag_indices, 
int nb_frag_indices, int track_id)
 {
-int i;
-MOVFragmentIndexItem * item;
+unsigned i;
+MOVFragmentIndex *frag_index = NULL;
 
-if (index < 0 || index >= frag_index->nb_items)
-return NULL;
-item = _index->item[index];
-for (i = 0; i < item->nb_stream_info; i++)
-if (item->stream_info[i].id == id)
-return >stream_info[i];
+for (i = 0; i < nb_frag_indices; i++)
+if (frag_indices[i].id == track_id)
+frag_index = _indices[i];
 
-// This shouldn't happen
-return NULL;
+return frag_index;
 }
 
-static void set_frag_stream(MOVFragmentIndex *frag_index, int id)
+static MOVFragmentStreamInfo *get_current_frag_stream_info(MOVContext *c, int 
id)
 {
-int i;
-MOVFragmentIndexItem * item;
+MOVFragmentIndex *frag_index = NULL;
 
-if (frag_index->current < 0 ||
-frag_index->current >= frag_index->nb_items)
-return;
-
-item = _index->item[frag_index->current];
-for (i = 0; i < item->nb_stream_info; i++)
-if (item->stream_info[i].id == id) {
-item->current = i;
-return;
-}
-
-// id not found.  This shouldn't happen.
-item->current = -1;
-}
-
-static MOVFragmentStreamInfo * get_current_frag_stream_info(
-MOVFragmentIndex *frag_index)
-{
-MOVFragmentIndexItem *item;
-if (frag_index->current < 0 ||
+frag_index = mov_find_frag_index(c->frag_indices, c->nb_frag_indices, id);
+if (!frag_index ||
+frag_index->current < 0 ||
 frag_index->current >= frag_index->nb_items)
 return NULL;
 
-item = _index->item[frag_index->current];
-if (item->current >= 0 && item->current < item->nb_stream_info)
-return >stream_info[item->current];
-
-// This shouldn't happen
-return NULL;
+return _index->item[frag_index->current].stream_info;
 }
 
 static int search_frag_moof_offset(MOVFragmentIndex *frag_index, int64_t 
offset)
@@ -1232,9 +1202,9 @@ static int search_frag_moof_offset(MOVFragmentIndex 
*frag_index, int64_t offset)
 return b;
 }
 
-static int64_t get_stream_info_time(MOVFragmentStreamInfo * frag_stream_info)
-{
-av_assert0(frag_stream_info);
+static int64_t get_frag_time(MOVFragmentIndex *frag_index,
+ int index, int track_id) {
+MOVFragmentStreamInfo *frag_stream_info = 
_index->item[index].stream_info;
 if (frag_stream_info->sidx_pts != AV_NOPTS_VALUE)
 return frag_stream_info->sidx_pts;
 if (frag_stream_info->first_tfra_pts != AV_NOPTS_VALUE)
@@ -1242,31 +1212,9 @@ static int64_t 

Re: [FFmpeg-devel] [PATCH 1/2] avcodec/v210dec: move DSP function setting into dedicated function

2019-03-06 Thread Paul B Mahol
On 3/6/19, Carl Eugen Hoyos  wrote:
> 2019-03-04 23:58 GMT+01:00, James Darnley :
>> Prepare for checkasm test.
>> ---
>>  libavcodec/v210dec.c | 13 +
>>  libavcodec/v210dec.h |  1 +
>>  2 files changed, 10 insertions(+), 4 deletions(-)
>>
>> diff --git a/libavcodec/v210dec.c b/libavcodec/v210dec.c
>> index ddc5dbe8be..28cf00d320 100644
>> --- a/libavcodec/v210dec.c
>> +++ b/libavcodec/v210dec.c
>> @@ -50,6 +50,14 @@ static void v210_planar_unpack_c(const uint32_t *src,
>> uint16_t *y, uint16_t *u,
>>  }
>>  }
>>
>> +av_cold void ff_v210dec_init(V210DecContext *s)
>> +{
>> +s->unpack_frame = v210_planar_unpack_c;
>
>> +s->aligned_input = 0;
>
> Isn't this an unrelated change or do I misunderstand?

You misunderstand.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] libavcodec/vp8dec: fix the multi-thread HWAccel decode error

2019-03-06 Thread Carl Eugen Hoyos
2019-03-06 9:25 GMT+01:00, Wang, Shaofei :
>> -Original Message-
>> From: ffmpeg-devel [mailto:ffmpeg-devel-boun...@ffmpeg.org] On Behalf Of
>> Carl Eugen Hoyos
>> Sent: Wednesday, March 6, 2019 3:49 PM
>> To: FFmpeg development discussions and patches 
>> Subject: Re: [FFmpeg-devel] [PATCH] libavcodec/vp8dec: fix the
>> multi-thread
>> HWAccel decode error
>>
>> 2018-08-09 9:09 GMT+02:00, Jun Zhao :
>> > the root cause is update_dimentions call get_pixel_format will trigger
>> > the hwaccel_uninit/hwaccel_init , in current context, there are 3
>> > situations in the update_dimentions():
>> > 1. First time calling. No matter single thread or multithread,
>> >get_pixel_format() should be called after dimentions were
>> >set;
>> > 2. Dimention changed at the runtime. Dimention need to be
>> >updated when macroblocks_base is already allocated,
>> >get_pixel_format() should be called to recreate new frames
>> >according to updated dimention;
>> > 3. Multithread first time calling. After decoder init, the
>> >other threads will call update_dimentions() at first time
>> >to allocate macroblocks_base and set dimentions.
>> >But get_pixel_format() is shouldn't be called due to low
>> >level frames and context are already created.
>> > In this fix, we only call update_dimentions as need.
>> >
>> > Signed-off-by: Wang, Shaofei 
>> > Reviewed-by: Jun, Zhao 
>> > ---
>> >  libavcodec/vp8.c |7 +--
>> >  1 files changed, 5 insertions(+), 2 deletions(-)
>> >
>> > diff --git a/libavcodec/vp8.c b/libavcodec/vp8.c index
>> > 3adfeac..18d1ada 100644
>> > --- a/libavcodec/vp8.c
>> > +++ b/libavcodec/vp8.c
>> > @@ -187,7 +187,7 @@ static av_always_inline  int
>> > update_dimensions(VP8Context *s, int width, int height, int is_vp7)  {
>> >  AVCodecContext *avctx = s->avctx;
>> > -int i, ret;
>> > +int i, ret, dim_reset = 0;
>> >
>> >  if (width  != s->avctx->width || ((width+15)/16 != s->mb_width ||
>> > (height+15)/16 != s->mb_height) && s->macroblocks_base ||
>> >  height != s->avctx->height) { @@ -196,9 +196,12 @@ int
>> > update_dimensions(VP8Context *s, int width, int height, int is_vp7)
>> >  ret = ff_set_dimensions(s->avctx, width, height);
>> >  if (ret < 0)
>> >  return ret;
>> > +
>> > +dim_reset = (s->macroblocks_base != NULL);
>> >  }
>> >
>> > -if (!s->actually_webp && !is_vp7) {
>> > +if ((s->pix_fmt == AV_PIX_FMT_NONE || dim_reset) &&
>> > + !s->actually_webp && !is_vp7) {
>>
>> Why is the new variable dim_reset needed?
>> Wouldn't the patch be simpler if you used s->macroblocks_base here?
> Since dim_reset was set in the "if" segment, it equal to
> (width != s->avctx->width || ((width+15)/16 != s->mb_width ||
> (height+15)/16 != s->mb_height) || height != s->avctx->height) &&
> s->macroblocks_base

Thank you!

Carl Eugen
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] libavcodec/vp8dec: fix the multi-thread HWAccel decode error

2019-03-06 Thread Wang, Shaofei
> -Original Message-
> From: ffmpeg-devel [mailto:ffmpeg-devel-boun...@ffmpeg.org] On Behalf Of
> Carl Eugen Hoyos
> Sent: Wednesday, March 6, 2019 3:49 PM
> To: FFmpeg development discussions and patches 
> Subject: Re: [FFmpeg-devel] [PATCH] libavcodec/vp8dec: fix the multi-thread
> HWAccel decode error
> 
> 2018-08-09 9:09 GMT+02:00, Jun Zhao :
> > the root cause is update_dimentions call get_pixel_format will trigger
> > the hwaccel_uninit/hwaccel_init , in current context, there are 3
> > situations in the update_dimentions():
> > 1. First time calling. No matter single thread or multithread,
> >get_pixel_format() should be called after dimentions were
> >set;
> > 2. Dimention changed at the runtime. Dimention need to be
> >updated when macroblocks_base is already allocated,
> >get_pixel_format() should be called to recreate new frames
> >according to updated dimention;
> > 3. Multithread first time calling. After decoder init, the
> >other threads will call update_dimentions() at first time
> >to allocate macroblocks_base and set dimentions.
> >But get_pixel_format() is shouldn't be called due to low
> >level frames and context are already created.
> > In this fix, we only call update_dimentions as need.
> >
> > Signed-off-by: Wang, Shaofei 
> > Reviewed-by: Jun, Zhao 
> > ---
> >  libavcodec/vp8.c |7 +--
> >  1 files changed, 5 insertions(+), 2 deletions(-)
> >
> > diff --git a/libavcodec/vp8.c b/libavcodec/vp8.c index
> > 3adfeac..18d1ada 100644
> > --- a/libavcodec/vp8.c
> > +++ b/libavcodec/vp8.c
> > @@ -187,7 +187,7 @@ static av_always_inline  int
> > update_dimensions(VP8Context *s, int width, int height, int is_vp7)  {
> >  AVCodecContext *avctx = s->avctx;
> > -int i, ret;
> > +int i, ret, dim_reset = 0;
> >
> >  if (width  != s->avctx->width || ((width+15)/16 != s->mb_width ||
> > (height+15)/16 != s->mb_height) && s->macroblocks_base ||
> >  height != s->avctx->height) { @@ -196,9 +196,12 @@ int
> > update_dimensions(VP8Context *s, int width, int height, int is_vp7)
> >  ret = ff_set_dimensions(s->avctx, width, height);
> >  if (ret < 0)
> >  return ret;
> > +
> > +dim_reset = (s->macroblocks_base != NULL);
> >  }
> >
> > -if (!s->actually_webp && !is_vp7) {
> > +if ((s->pix_fmt == AV_PIX_FMT_NONE || dim_reset) &&
> > + !s->actually_webp && !is_vp7) {
> 
> Why is the new variable dim_reset needed?
> Wouldn't the patch be simpler if you used s->macroblocks_base here?
Since dim_reset was set in the "if" segment, it equal to
(width != s->avctx->width || ((width+15)/16 != s->mb_width ||
(height+15)/16 != s->mb_height) || height != s->avctx->height) && 
s->macroblocks_base

> 
> Carl Eugen
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH] lavc/h264_levels: add MaxMBPS checking and update fate test.

2019-03-06 Thread Decai Lin
1. add MaxMBPS checking for level idc setting to align with AVC spec
   AnnexA table A-1/A-6 level limits.
2. update h264 level fate test.

Signed-off-by: Decai Lin 
---
 libavcodec/h264_levels.c   |  5 +
 libavcodec/h264_levels.h   |  1 +
 libavcodec/h264_metadata_bsf.c | 14 +-
 libavcodec/tests/h264_levels.c | 41 ++---
 libavcodec/vaapi_encode_h264.c | 13 +
 5 files changed, 70 insertions(+), 4 deletions(-)

diff --git a/libavcodec/h264_levels.c b/libavcodec/h264_levels.c
index 7a55116..e457dbe 100644
--- a/libavcodec/h264_levels.c
+++ b/libavcodec/h264_levels.c
@@ -89,11 +89,13 @@ const H264LevelDescriptor *ff_h264_get_level(int level_idc,
 
 const H264LevelDescriptor *ff_h264_guess_level(int profile_idc,
int64_t bitrate,
+   int framerate,
int width, int height,
int max_dec_frame_buffering)
 {
 int width_mbs  = (width  + 15) / 16;
 int height_mbs = (height + 15) / 16;
+int64_t mb_processing_rate = (int64_t) (width_mbs * height_mbs * 
framerate);
 int no_cs3f = !(profile_idc == 66 ||
 profile_idc == 77 ||
 profile_idc == 88);
@@ -108,6 +110,9 @@ const H264LevelDescriptor *ff_h264_guess_level(int 
profile_idc,
 if (bitrate > (int64_t)level->max_br * h264_get_br_factor(profile_idc))
 continue;
 
+if (mb_processing_rate > (int64_t)level->max_mbps)
+continue;
+
 if (width_mbs  * height_mbs > level->max_fs)
 continue;
 if (width_mbs  * width_mbs  > 8 * level->max_fs)
diff --git a/libavcodec/h264_levels.h b/libavcodec/h264_levels.h
index 4189fc6..0a0f410 100644
--- a/libavcodec/h264_levels.h
+++ b/libavcodec/h264_levels.h
@@ -46,6 +46,7 @@ const H264LevelDescriptor *ff_h264_get_level(int level_idc,
  */
 const H264LevelDescriptor *ff_h264_guess_level(int profile_idc,
int64_t bitrate,
+   int framerate,
int width, int height,
int max_dec_frame_buffering);
 
diff --git a/libavcodec/h264_metadata_bsf.c b/libavcodec/h264_metadata_bsf.c
index a17987a..61c2711 100644
--- a/libavcodec/h264_metadata_bsf.c
+++ b/libavcodec/h264_metadata_bsf.c
@@ -223,6 +223,7 @@ static int h264_metadata_update_sps(AVBSFContext *bsf,
 const H264LevelDescriptor *desc;
 int64_t bit_rate;
 int width, height, dpb_frames;
+int framerate, fr_num, fr_den;
 
 if (sps->vui.nal_hrd_parameters_present_flag) {
 bit_rate = 
(sps->vui.nal_hrd_parameters.bit_rate_value_minus1[0] + 1) *
@@ -244,7 +245,18 @@ static int h264_metadata_update_sps(AVBSFContext *bsf,
 height = 16 * (sps->pic_height_in_map_units_minus1 + 1) *
 (2 - sps->frame_mbs_only_flag);
 
-desc = ff_h264_guess_level(sps->profile_idc, bit_rate,
+if (ctx->tick_rate.num > 0 && ctx->tick_rate.den > 0)
+av_reduce(_num, _den,
+ctx->tick_rate.num, ctx->tick_rate.den, 65535);
+else
+av_reduce(_num, _den,
+ctx->tick_rate.den, ctx->tick_rate.num, 65535);
+if (fr_den > 0)
+framerate = fr_num / fr_den;
+else
+framerate = fr_num;
+
+desc = ff_h264_guess_level(sps->profile_idc, bit_rate, framerate,
width, height, dpb_frames);
 if (desc) {
 level_idc = desc->level_idc;
diff --git a/libavcodec/tests/h264_levels.c b/libavcodec/tests/h264_levels.c
index 0e00f05..6176c0b 100644
--- a/libavcodec/tests/h264_levels.c
+++ b/libavcodec/tests/h264_levels.c
@@ -62,6 +62,31 @@ static const struct {
 static const struct {
 int width;
 int height;
+int framerate;
+int level_idc;
+} test_framerate[] = {
+// Some typical sizes and frame rates.
+// (From H.264 table A-1 and table A-6)
+{  176,  144,  15, 10 },
+{  320,  240,  10, 11 },
+{  352,  288,  30, 13 },
+{  352,  576,  25, 21 },
+{  640,  480,  33, 30 },
+{  720,  576,  25, 30 },
+{ 1024,  768,  35, 31 },
+{ 1280,  720,  30, 31 },
+{ 1280, 1024,  42, 32 },
+{ 1920, 1088,  30, 40 },
+{ 2048, 1024,  30, 40 },
+{ 2048, 1088,  60, 42 },
+{ 3680, 1536,  26, 50 },
+{ 4096, 2048,  30, 51 },
+{ 4096, 2160,  60, 52 },
+};
+
+static const struct {
+int width;
+int height;
 int dpb_size;
 int level_idc;
 } test_dpb[] = {
@@ -147,14 +172,23 @@ int main(void)
 } while (0)
 
 for (i = 0; i < FF_ARRAY_ELEMS(test_sizes); i++) {
-level = 

Re: [FFmpeg-devel] [PATCH 1/2] avcodec/v210dec: move DSP function setting into dedicated function

2019-03-06 Thread Carl Eugen Hoyos
2019-03-04 23:58 GMT+01:00, James Darnley :
> Prepare for checkasm test.
> ---
>  libavcodec/v210dec.c | 13 +
>  libavcodec/v210dec.h |  1 +
>  2 files changed, 10 insertions(+), 4 deletions(-)
>
> diff --git a/libavcodec/v210dec.c b/libavcodec/v210dec.c
> index ddc5dbe8be..28cf00d320 100644
> --- a/libavcodec/v210dec.c
> +++ b/libavcodec/v210dec.c
> @@ -50,6 +50,14 @@ static void v210_planar_unpack_c(const uint32_t *src,
> uint16_t *y, uint16_t *u,
>  }
>  }
>
> +av_cold void ff_v210dec_init(V210DecContext *s)
> +{
> +s->unpack_frame = v210_planar_unpack_c;

> +s->aligned_input = 0;

Isn't this an unrelated change or do I misunderstand?

Carl Eugen
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] avutil/mem: Mark DECLARE_ASM_ALIGNED as visibility("hidden") for __GNUC__

2019-03-06 Thread Carl Eugen Hoyos
2019-02-21 2:37 GMT+01:00, Fāng-ruì Sòng :
> Sorry if this doesn't attach to the correct thread as I didn't
> subscribe to this list and don't know the Message-ID of the thread.

The thread works fine here with gmail but your patch was corrupted,
you have to attach it.

Carl Eugen
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 1/1] avformat/dashenc: Added #EXT-X-PROGRAM-DATE-TIME to HLS playlists

2019-03-06 Thread Joep Admiraal
Thanks for reviewing and making this happen.

Regards,
Joep

On Wed, Mar 6, 2019 at 6:38 AM Jeyapal, Karthick 
wrote:

>
> On 3/5/19 8:07 PM, joepadmiraal wrote:
> > ---
> >  libavformat/dashenc.c | 20 ++--
> >  1 file changed, 18 insertions(+), 2 deletions(-)
> >
> > diff --git a/libavformat/dashenc.c b/libavformat/dashenc.c
> > index c5e882f4ae..6bcdc9ba36 100644
> > --- a/libavformat/dashenc.c
> > +++ b/libavformat/dashenc.c
> > @@ -61,6 +61,7 @@ typedef struct Segment {
> >  int64_t start_pos;
> >  int range_length, index_length;
> >  int64_t time;
> > +double prog_date_time;
> >  int64_t duration;
> >  int n;
> >  } Segment;
> > @@ -122,6 +123,7 @@ typedef struct DASHContext {
> >  int64_t last_duration;
> >  int64_t total_duration;
> >  char availability_start_time[100];
> > +time_t start_time_s;
> >  char dirname[1024];
> >  const char *single_file_name;  /* file names as specified in
> options */
> >  const char *init_seg_name;
> > @@ -433,6 +435,7 @@ static void write_hls_media_playlist(OutputStream
> *os, AVFormatContext *s,
> >  const char *proto = avio_find_protocol_name(c->dirname);
> >  int use_rename = proto && !strcmp(proto, "file");
> >  int i, start_index, start_number;
> > +double prog_date_time = 0;
> >
> >  get_start_index_number(os, c, _index, _number);
> >
> > @@ -467,11 +470,20 @@ static void write_hls_media_playlist(OutputStream
> *os, AVFormatContext *s,
> >
> >  for (i = start_index; i < os->nb_segments; i++) {
> >  Segment *seg = os->segments[i];
> > +
> > +if (prog_date_time == 0) {
> > +if (os->nb_segments == 1)
> > +prog_date_time = c->start_time_s;
> > +else
> > +prog_date_time = seg->prog_date_time;
> > +}
> > +seg->prog_date_time = prog_date_time;
> > +
> >  ret = ff_hls_write_file_entry(c->m3u8_out, 0, c->single_file,
> >  (double) seg->duration / timescale, 0,
> >  seg->range_length, seg->start_pos, NULL,
> >  c->single_file ? os->initfile :
> seg->file,
> > -NULL);
> > +_date_time);
> >  if (ret < 0) {
> >  av_log(os->ctx, AV_LOG_WARNING, "ff_hls_write_file_entry
> get error\n");
> >  }
> > @@ -1592,9 +1604,13 @@ static int dash_write_packet(AVFormatContext *s,
> AVPacket *pkt)
> >  os->first_pts = pkt->pts;
> >  os->last_pts = pkt->pts;
> >
> > -if (!c->availability_start_time[0])
> > +if (!c->availability_start_time[0]) {
> > +int64_t start_time_us = av_gettime();
> > +int64_t start_time_ms = start_time_us / 1000;
> > +c->start_time_s = start_time_ms / 1000;
> >  format_date_now(c->availability_start_time,
> >  sizeof(c->availability_start_time));
> > +}
> >
> >  if (!os->availability_time_offset && pkt->duration) {
> >  int64_t frame_duration = av_rescale_q(pkt->duration,
> st->time_base,
> Thanks for your contribution. This patch has been pushed (after a minor
> cleanup).
>
> Regards,
> Karthick
>
>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] libdav1d: Add support for reading hdr10 metadata

2019-03-06 Thread Carl Eugen Hoyos
2019-03-05 19:26 GMT+01:00, James Almer :
> On 3/5/2019 3:19 PM, Vittorio Giovara wrote:

>> +if (p->mastering_display) {
>> +AVMasteringDisplayMetadata *mastering =
>> av_mastering_display_metadata_create_side_data(frame);
>> +if (!mastering)
>> +return AVERROR(ENOMEM);
>> +
>> +for (i = 0; i < 3; i++) {
>
> for (int i = 0,...)

Being allowed to use doesn't mean it has to be used, no?
There also is a smaller scope...

Carl Eugen
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 2/2] avcodec/libdav1d: use a custom picture allocator

2019-03-06 Thread Carl Eugen Hoyos
2019-03-04 22:06 GMT+01:00, James Almer :

> +static const enum AVPixelFormat pix_fmt[][3] = {
> +[DAV1D_PIXEL_LAYOUT_I400] = { AV_PIX_FMT_GRAY8,   AV_PIX_FMT_GRAY10,
> AV_PIX_FMT_GRAY12 },
> +[DAV1D_PIXEL_LAYOUT_I420] = { AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUV420P10,
> AV_PIX_FMT_YUV420P12 },
> +[DAV1D_PIXEL_LAYOUT_I422] = { AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUV422P10,
> AV_PIX_FMT_YUV422P12 },
> +[DAV1D_PIXEL_LAYOUT_I444] = { AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUV444P10,
> AV_PIX_FMT_YUV444P12 },
> +};

Looks like a separate change.

And please use the ERROR defines.

Carl Eugen
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH v6 1/2] lavc/svt_hevc: add libsvt hevc encoder wrapper.

2019-03-06 Thread Carl Eugen Hoyos
2019-03-05 8:43 GMT+01:00, Jing SUN :

> +enabled libsvthevc&& require_pkg_config libsvthevc SvtHevcEnc
> svt-hevc/EbApi.h EbInitHandle

What funny optional dependencies does this library have that
justifies requiring pkg_config?

Carl Eugen
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel