Re: [FFmpeg-devel] [PATCH v3 26/41] lavc/h264: Add common code for level handling

2018-08-23 Thread James Almer
On 8/22/2018 8:44 PM, Mark Thompson wrote:
> Including a unit test.
> ---
>  libavcodec/Makefile|   3 +-
>  libavcodec/h264_levels.c   | 130 +++
>  libavcodec/h264_levels.h   |  53 ++
>  libavcodec/tests/.gitignore|   1 +
>  libavcodec/tests/h264_levels.c | 183 +
>  tests/fate/libavcodec.mak  |   5 +
>  6 files changed, 374 insertions(+), 1 deletion(-)
>  create mode 100644 libavcodec/h264_levels.c
>  create mode 100644 libavcodec/h264_levels.h
>  create mode 100644 libavcodec/tests/h264_levels.c
> 
> diff --git a/libavcodec/Makefile b/libavcodec/Makefile
> index cbbfc9af2e..d07a9073af 100644
> --- a/libavcodec/Makefile
> +++ b/libavcodec/Makefile
> @@ -355,7 +355,7 @@ OBJS-$(CONFIG_H264_OMX_ENCODER)+= omx.o
>  OBJS-$(CONFIG_H264_QSV_DECODER)+= qsvdec_h2645.o
>  OBJS-$(CONFIG_H264_QSV_ENCODER)+= qsvenc_h264.o
>  OBJS-$(CONFIG_H264_RKMPP_DECODER)  += rkmppdec.o
> -OBJS-$(CONFIG_H264_VAAPI_ENCODER)  += vaapi_encode_h264.o
> +OBJS-$(CONFIG_H264_VAAPI_ENCODER)  += h264_levels.o vaapi_encode_h264.o
>  OBJS-$(CONFIG_H264_VIDEOTOOLBOX_ENCODER) += videotoolboxenc.o
>  OBJS-$(CONFIG_H264_V4L2M2M_DECODER)+= v4l2_m2m_dec.o
>  OBJS-$(CONFIG_H264_V4L2M2M_ENCODER)+= v4l2_m2m_enc.o
> @@ -1134,6 +1134,7 @@ TESTPROGS-$(CONFIG_IDCTDSP)   += dct
>  TESTPROGS-$(CONFIG_IIRFILTER) += iirfilter
>  TESTPROGS-$(HAVE_MMX) += motion
>  TESTPROGS-$(CONFIG_MPEGVIDEO) += mpeg12framerate
> +TESTPROGS-$(CONFIG_H264_VAAPI_ENCODER)+= h264_levels

Needing h264_vaapi_encoder to test this is not ideal. You'd be limiting
the amount of fate clients testing an internal module to those with an
unrelated external encoder enabled.

Maybe just add h264_levels.o to h264parse, and check for that instead?
Alternatively, since you need to add that object to h264_metadata to fix
the build failure Michael reported for patch 28, you could check for
that bsf instead.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH v3 26/41] lavc/h264: Add common code for level handling

2018-08-22 Thread Mark Thompson
Including a unit test.
---
 libavcodec/Makefile|   3 +-
 libavcodec/h264_levels.c   | 130 +++
 libavcodec/h264_levels.h   |  53 ++
 libavcodec/tests/.gitignore|   1 +
 libavcodec/tests/h264_levels.c | 183 +
 tests/fate/libavcodec.mak  |   5 +
 6 files changed, 374 insertions(+), 1 deletion(-)
 create mode 100644 libavcodec/h264_levels.c
 create mode 100644 libavcodec/h264_levels.h
 create mode 100644 libavcodec/tests/h264_levels.c

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index cbbfc9af2e..d07a9073af 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -355,7 +355,7 @@ OBJS-$(CONFIG_H264_OMX_ENCODER)+= omx.o
 OBJS-$(CONFIG_H264_QSV_DECODER)+= qsvdec_h2645.o
 OBJS-$(CONFIG_H264_QSV_ENCODER)+= qsvenc_h264.o
 OBJS-$(CONFIG_H264_RKMPP_DECODER)  += rkmppdec.o
-OBJS-$(CONFIG_H264_VAAPI_ENCODER)  += vaapi_encode_h264.o
+OBJS-$(CONFIG_H264_VAAPI_ENCODER)  += h264_levels.o vaapi_encode_h264.o
 OBJS-$(CONFIG_H264_VIDEOTOOLBOX_ENCODER) += videotoolboxenc.o
 OBJS-$(CONFIG_H264_V4L2M2M_DECODER)+= v4l2_m2m_dec.o
 OBJS-$(CONFIG_H264_V4L2M2M_ENCODER)+= v4l2_m2m_enc.o
@@ -1134,6 +1134,7 @@ TESTPROGS-$(CONFIG_IDCTDSP)   += dct
 TESTPROGS-$(CONFIG_IIRFILTER) += iirfilter
 TESTPROGS-$(HAVE_MMX) += motion
 TESTPROGS-$(CONFIG_MPEGVIDEO) += mpeg12framerate
+TESTPROGS-$(CONFIG_H264_VAAPI_ENCODER)+= h264_levels
 TESTPROGS-$(CONFIG_RANGECODER)+= rangecoder
 TESTPROGS-$(CONFIG_SNOW_ENCODER)  += snowenc
 
diff --git a/libavcodec/h264_levels.c b/libavcodec/h264_levels.c
new file mode 100644
index 00..6b4e18a914
--- /dev/null
+++ b/libavcodec/h264_levels.c
@@ -0,0 +1,130 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "avcodec.h"
+#include "h264_levels.h"
+
+// H.264 table A-1.
+static const H264LevelDescriptor h264_levels[] = {
+// Name  MaxMBPS   MaxBR  MinCR
+//  | level_idc |   MaxFS|MaxCPB| 
MaxMvsPer2Mb
+//  | | cs3f| |  MaxDpbMbs   |   |  MaxVmvR |   |
+{ "1",   10, 0, 1485, 99,396, 64,175,   64, 2,  0 },
+{ "1b",  10, 1, 1485, 99,396,128,350,   64, 2,  0 },
+{ "1b",   9, 0, 1485, 99,396,128,350,   64, 2,  0 },
+{ "1.1", 11, 0, 3000,396,900,192,500,  128, 2,  0 },
+{ "1.2", 12, 0, 6000,396,   2376,384,   1000,  128, 2,  0 },
+{ "1.3", 13, 0,11880,396,   2376,768,   2000,  128, 2,  0 },
+{ "2",   20, 0,11880,396,   2376,   2000,   2000,  128, 2,  0 },
+{ "2.1", 21, 0,19800,792,   4752,   4000,   4000,  256, 2,  0 },
+{ "2.2", 22, 0,20250,   1620,   8100,   4000,   4000,  256, 2,  0 },
+{ "3",   30, 0,40500,   1620,   8100,  1,  1,  256, 2, 32 },
+{ "3.1", 31, 0,   108000,   3600,  18000,  14000,  14000,  512, 4, 16 },
+{ "3.2", 32, 0,   216000,   5120,  20480,  2,  2,  512, 4, 16 },
+{ "4",   40, 0,   245760,   8192,  32768,  2,  25000,  512, 4, 16 },
+{ "4.1", 41, 0,   245760,   8192,  32768,  5,  62500,  512, 2, 16 },
+{ "4.2", 42, 0,   522240,   8704,  34816,  5,  62500,  512, 2, 16 },
+{ "5",   50, 0,   589824,  22080, 110400, 135000, 135000,  512, 2, 16 },
+{ "5.1", 51, 0,   983040,  36864, 184320, 24, 24,  512, 2, 16 },
+{ "5.2", 52, 0,  2073600,  36864, 184320, 24, 24,  512, 2, 16 },
+{ "6",   60, 0,  4177920, 139264, 696320, 24, 24, 8192, 2, 16 },
+{ "6.1", 61, 0,  8355840, 139264, 696320, 48, 48, 8192, 2, 16 },
+{ "6.2", 62, 0, 16711680, 139264, 696320, 80, 80, 8192, 2, 16 },
+};
+
+// H.264 table A-2 plus values from A-1.
+static const struct {
+int profile_idc;
+int cpb_br_vcl_factor;
+int cpb_br_nal_factor;
+} h264_br_factors[] = {
+{  66, 1000, 1200 },
+{  77, 1000, 1200 },
+{  88, 1000, 1200 },
+{ 100, 1250, 1500 },
+{ 110, 3000, 3600 },
+{ 122, 4000, 4800 },
+{ 244, 4000, 4800 },
+{  44, 4000, 4800 },
+};
+
+// We are only ever