[FFmpeg-devel] [PATCH 2/2] ffmpeg: don't delay printing initial stats

2020-12-21 Thread Gyan Doshi
The first stats is printed after the initial stats_period has elapsed. With a 
large period,
it may appear that ffmpeg has frozen at startup.

The initial stats is now printed after the first transcode_step.
---
 fftools/ffmpeg.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 6d25f1bca9..2c0820aacf 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -1685,6 +1685,7 @@ static void print_report(int is_last_report, int64_t 
timer_start, int64_t cur_ti
 double speed;
 int64_t pts = INT64_MIN + 1;
 static int64_t last_time = -1;
+static int first_report = 1;
 static int qp_histogram[52];
 int hours, mins, secs, us;
 const char *hours_sign;
@@ -1697,9 +1698,8 @@ static void print_report(int is_last_report, int64_t 
timer_start, int64_t cur_ti
 if (!is_last_report) {
 if (last_time == -1) {
 last_time = cur_time;
-return;
 }
-if ((cur_time - last_time) < stats_period)
+if ((cur_time - last_time) < stats_period && !first_report)
 return;
 last_time = cur_time;
 }
@@ -1876,6 +1876,8 @@ static void print_report(int is_last_report, int64_t 
timer_start, int64_t cur_ti
 }
 }
 
+first_report = 0;
+
 if (is_last_report)
 print_final_stats(total_size);
 }
-- 
2.27.0

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

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

[FFmpeg-devel] [PATCH 1/2] ffmpeg: add option stats_period

2020-12-21 Thread Gyan Doshi
At present, progress stats are updated at a hardcoded interval of
half a second. For long processes, this can lead to bloated
logs and progress reports.

Users can now set a custom period using option -stats_period
Default is kept at 0.5 seconds.
---
 doc/ffmpeg.texi  |  7 ++-
 fftools/ffmpeg.c |  2 +-
 fftools/ffmpeg.h |  1 +
 fftools/ffmpeg_opt.c | 18 ++
 4 files changed, 26 insertions(+), 2 deletions(-)

diff --git a/doc/ffmpeg.texi b/doc/ffmpeg.texi
index 95d6463685..62015d7565 100644
--- a/doc/ffmpeg.texi
+++ b/doc/ffmpeg.texi
@@ -675,14 +675,19 @@ Specify the preset for matching stream(s).
 Print encoding progress/statistics. It is on by default, to explicitly
 disable it you need to specify @code{-nostats}.
 
+@item -stats_period @var{time} (@emph{global})
+Set period at which encoding progress/statistics are updated. Default is 0.5 
seconds.
+
 @item -progress @var{url} (@emph{global})
 Send program-friendly progress information to @var{url}.
 
-Progress information is written approximately every second and at the end of
+Progress information is written periodically and at the end of
 the encoding process. It is made of "@var{key}=@var{value}" lines. @var{key}
 consists of only alphanumeric characters. The last key of a sequence of
 progress information is always "progress".
 
+The update period is set using @code{-stats_period}.
+
 @anchor{stdin option}
 @item -stdin
 Enable interaction on standard input. On by default unless standard input is
diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index b446d9b206..6d25f1bca9 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -1699,7 +1699,7 @@ static void print_report(int is_last_report, int64_t 
timer_start, int64_t cur_ti
 last_time = cur_time;
 return;
 }
-if ((cur_time - last_time) < 50)
+if ((cur_time - last_time) < stats_period)
 return;
 last_time = cur_time;
 }
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 3b54dab7fc..8046e75026 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -614,6 +614,7 @@ extern int debug_ts;
 extern int exit_on_error;
 extern int abort_on_flags;
 extern int print_stats;
+extern int64_t stats_period;
 extern int qp_hist;
 extern int stdin_interaction;
 extern int frame_bits_per_raw_sample;
diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c
index 7ee034c9c9..242468fc64 100644
--- a/fftools/ffmpeg_opt.c
+++ b/fftools/ffmpeg_opt.c
@@ -174,6 +174,7 @@ int filter_nbthreads = 0;
 int filter_complex_nbthreads = 0;
 int vstats_version = 2;
 int auto_conversion_filters = 1;
+int64_t stats_period = 50;
 
 
 static int intra_only = 0;
@@ -282,6 +283,21 @@ static int opt_abort_on(void *optctx, const char *opt, 
const char *arg)
 return av_opt_eval_flags(&pclass, &opts[0], arg, &abort_on_flags);
 }
 
+static int opt_stats_period(void *optctx, const char *opt, const char *arg)
+{
+int64_t user_stats_period = parse_time_or_die(opt, arg, 1);
+
+if (user_stats_period <= 0) {
+av_log(NULL, AV_LOG_ERROR, "stats_period %s must be positive.\n", arg);
+return AVERROR(EINVAL);
+}
+
+stats_period = user_stats_period;
+av_log(NULL, AV_LOG_INFO, "ffmpeg stats and -progress period set to 
%s.\n", arg);
+
+return 0;
+}
+
 static int opt_sameq(void *optctx, const char *opt, const char *arg)
 {
 av_log(NULL, AV_LOG_ERROR, "Option '%s' was removed. "
@@ -3557,6 +3573,8 @@ const OptionDef options[] = {
 "enable automatic conversion filters globally" },
 { "stats",  OPT_BOOL,{ 
&print_stats },
 "print progress report during encoding", },
+{ "stats_period",HAS_ARG | OPT_EXPERT,   { 
.func_arg = opt_stats_period },
+"set the period at which ffmpeg updates stats and -progress output", 
"time" },
 { "attach", HAS_ARG | OPT_PERFILE | OPT_EXPERT |
 OPT_OUTPUT,  { 
.func_arg = opt_attach },
 "add an attachment to the output file", "filename" },
-- 
2.27.0

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

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

Re: [FFmpeg-devel] [PATCH 7/8] avformat/aviobuf: Check for overflow in ffio_read_varlen()

2020-12-21 Thread Andreas Rheinhardt
Michael Niedermayer:
> No testcase
> 
> Signed-off-by: Michael Niedermayer 
> ---
>  libavformat/aviobuf.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c
> index 78cc60b2ae..7730547106 100644
> --- a/libavformat/aviobuf.c
> +++ b/libavformat/aviobuf.c
> @@ -917,6 +917,8 @@ uint64_t ffio_read_varlen(AVIOContext *bc){
>  
>  do{
>  tmp = avio_r8(bc);
> +if (val > UINT64_MAX>>7)
> +return AVERROR_INVALIDDATA;
>  val= (val<<7) + (tmp&127);
>  }while(tmp&128);
>  return val;
> 
The error can't be detected at all given that the function returns an
uint64_t.

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

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

Re: [FFmpeg-devel] [PATCH 14/39] avcodec/h261dec: Don't use too big max_depth in get_vlc2()

2020-12-21 Thread Andreas Rheinhardt
Michael Niedermayer:
> On Thu, Dec 10, 2020 at 12:16:32PM +0100, Andreas Rheinhardt wrote:
>> Signed-off-by: Andreas Rheinhardt 
>> ---
>>  libavcodec/h261dec.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> ok assuming its not better to make H261_CBP_VLC_BITS smaller
> 
> thx
> 
> [...]
> 
Honestly, I don't care either way. Do you have a preference?

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

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

[FFmpeg-devel] [PATCH] libswscale: avoid UB nullptr-with-offset.

2020-12-21 Thread jleconte
---
 libswscale/slice.c| 12 +---
 libswscale/swscale_unscaled.c |  5 +++--
 2 files changed, 8 insertions(+), 9 deletions(-)

diff --git a/libswscale/slice.c b/libswscale/slice.c
index 7849b70f4d..b1cfc0e506 100644
--- a/libswscale/slice.c
+++ b/libswscale/slice.c
@@ -158,14 +158,12 @@ int ff_init_slice_from_src(SwsSlice * s, uint8_t *src[4], 
int stride[4], int src
 chrY + chrH,
 lumY + lumH};
 
-uint8_t *const src_[4] = {src[0] + (relative ? 0 : start[0]) * stride[0],
-  src[1] + (relative ? 0 : start[1]) * stride[1],
-  src[2] + (relative ? 0 : start[2]) * stride[2],
-  src[3] + (relative ? 0 : start[3]) * stride[3]};
-
 s->width = srcW;
 
 for (i = 0; i < 4; ++i) {
+if (!src[i])
+  continue;
+uint8_t *const src_ = src[i] + (relative ? 0 : start[i]) * stride[i];
 int j;
 int first = s->plane[i].sliceY;
 int n = s->plane[i].available_lines;
@@ -175,13 +173,13 @@ int ff_init_slice_from_src(SwsSlice * s, uint8_t *src[4], 
int stride[4], int src
 if (start[i] >= first && n >= tot_lines) {
 s->plane[i].sliceH = FFMAX(tot_lines, s->plane[i].sliceH);
 for (j = 0; j < lines; j+= 1)
-s->plane[i].line[start[i] - first + j] = src_[i] +  j * 
stride[i];
+s->plane[i].line[start[i] - first + j] = src_ +  j * stride[i];
 } else {
 s->plane[i].sliceY = start[i];
 lines = lines > n ? n : lines;
 s->plane[i].sliceH = lines;
 for (j = 0; j < lines; j+= 1)
-s->plane[i].line[j] = src_[i] +  j * stride[i];
+s->plane[i].line[j] = src_ +  j * stride[i];
 }
 
 }
diff --git a/libswscale/swscale_unscaled.c b/libswscale/swscale_unscaled.c
index 563de39696..39fb7cc87f 100644
--- a/libswscale/swscale_unscaled.c
+++ b/libswscale/swscale_unscaled.c
@@ -1806,6 +1806,9 @@ static int planarCopyWrapper(SwsContext *c, const uint8_t 
*src[],
 const AVPixFmtDescriptor *desc_dst = av_pix_fmt_desc_get(c->dstFormat);
 int plane, i, j;
 for (plane = 0; plane < 4; plane++) {
+if (!dst[plane])
+continue;
+
 int length = (plane == 0 || plane == 3) ? c->srcW  : 
AV_CEIL_RSHIFT(c->srcW,   c->chrDstHSubSample);
 int y =  (plane == 0 || plane == 3) ? srcSliceY: 
AV_CEIL_RSHIFT(srcSliceY, c->chrDstVSubSample);
 int height = (plane == 0 || plane == 3) ? srcSliceH: 
AV_CEIL_RSHIFT(srcSliceH, c->chrDstVSubSample);
@@ -1813,8 +1816,6 @@ static int planarCopyWrapper(SwsContext *c, const uint8_t 
*src[],
 uint8_t *dstPtr = dst[plane] + dstStride[plane] * y;
 int shiftonly = plane == 1 || plane == 2 || (!c->srcRange && plane == 
0);
 
-if (!dst[plane])
-continue;
 // ignore palette for GRAY8
 if (plane == 1 && !dst[2]) continue;
 if (!src[plane] || (plane == 1 && !src[2])) {
-- 
2.29.2.684.gfbc64c5ab5-goog

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

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

Re: [FFmpeg-devel] [PATCH 2/6] avcodec: add h266 codec id and profiles

2020-12-21 Thread James Almer

On 12/21/2020 3:07 AM, Nuo Mi wrote:

---
  libavcodec/avcodec.h| 2 ++
  libavcodec/codec_desc.c | 8 
  libavcodec/codec_id.h   | 2 ++
  libavcodec/profiles.c   | 5 +
  libavcodec/profiles.h   | 1 +
  5 files changed, 18 insertions(+)

diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 1d3099d50a..f7ea4d5849 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -1961,6 +1961,8 @@ typedef struct AVCodecContext {
  #define FF_PROFILE_HEVC_MAIN_STILL_PICTURE  3
  #define FF_PROFILE_HEVC_REXT4
  
+#define FF_PROFILE_H266_MAIN_10  1


We should decide first what we are going to use, if VVC or h266.

My suggestion was to use VVC for decoder, parser, demuxer and public 
defines, which is what's exposed to the user, and h266 for CBS, which 
makes things simpler to implement and is proper consider it's written 
using the ITU spec.



+
  #define FF_PROFILE_AV1_MAIN 0
  #define FF_PROFILE_AV1_HIGH 1
  #define FF_PROFILE_AV1_PROFESSIONAL 2
diff --git a/libavcodec/codec_desc.c b/libavcodec/codec_desc.c
index 404c460f8f..62fe0f453d 100644
--- a/libavcodec/codec_desc.c
+++ b/libavcodec/codec_desc.c
@@ -1426,6 +1426,14 @@ static const AVCodecDescriptor codec_descriptors[] = {
  .long_name = NULL_IF_CONFIG_SMALL("Microsoft Paint (MSP) version 2"),
  .props = AV_CODEC_PROP_INTRA_ONLY | AV_CODEC_PROP_LOSSLESS,
  },
+{
+.id= AV_CODEC_ID_H266,
+.type  = AVMEDIA_TYPE_VIDEO,
+.name  = "h266",


Ditto.


+.long_name = NULL_IF_CONFIG_SMALL("H.266 / VVC (Versatile Video 
Coding)"),
+.props = AV_CODEC_PROP_LOSSY | AV_CODEC_PROP_REORDER,
+.profiles  = NULL_IF_CONFIG_SMALL(ff_h266_profiles),
+},
  {
  .id= AV_CODEC_ID_Y41P,
  .type  = AVMEDIA_TYPE_VIDEO,
diff --git a/libavcodec/codec_id.h b/libavcodec/codec_id.h
index 6133e03bb9..7a8a896bfe 100644
--- a/libavcodec/codec_id.h
+++ b/libavcodec/codec_id.h
@@ -244,6 +244,8 @@ enum AVCodecID {
  AV_CODEC_ID_PGX,
  AV_CODEC_ID_AVS3,
  AV_CODEC_ID_MSP2,
+AV_CODEC_ID_VVC,
+#define AV_CODEC_ID_H266 AV_CODEC_ID_VVC


This chunk is good as is.

  
  AV_CODEC_ID_Y41P = 0x8000,

  AV_CODEC_ID_AVRP,
diff --git a/libavcodec/profiles.c b/libavcodec/profiles.c
index e59a3a5c12..710f2c01e2 100644
--- a/libavcodec/profiles.c
+++ b/libavcodec/profiles.c
@@ -74,6 +74,11 @@ const AVProfile ff_h264_profiles[] = {
  { FF_PROFILE_UNKNOWN },
  };
  
+const AVProfile ff_h266_profiles[] = {

+{ FF_PROFILE_H266_MAIN_10, "Main 10" },
+{ FF_PROFILE_UNKNOWN },
+};
+
  const AVProfile ff_hevc_profiles[] = {
  { FF_PROFILE_HEVC_MAIN, "Main"},
  { FF_PROFILE_HEVC_MAIN_10,  "Main 10" },
diff --git a/libavcodec/profiles.h b/libavcodec/profiles.h
index 6baaba5701..7a353dbf3d 100644
--- a/libavcodec/profiles.h
+++ b/libavcodec/profiles.h
@@ -60,6 +60,7 @@ extern const AVProfile ff_aac_profiles[];
  extern const AVProfile ff_dca_profiles[];
  extern const AVProfile ff_dnxhd_profiles[];
  extern const AVProfile ff_h264_profiles[];
+extern const AVProfile ff_h266_profiles[];
  extern const AVProfile ff_hevc_profiles[];
  extern const AVProfile ff_jpeg2000_profiles[];
  extern const AVProfile ff_mpeg2_video_profiles[];



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

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

Re: [FFmpeg-devel] [PATCH 5/6] avcodec: add h266 parser

2020-12-21 Thread James Almer

On 12/21/2020 3:07 AM, Nuo Mi wrote:

---
  configure|   3 +
  libavcodec/Makefile  |   1 +
  libavcodec/h2645_parse.c |  73 +-
  libavcodec/h266_parser.c | 284 +++
  libavcodec/parsers.c |   1 +
  5 files changed, 360 insertions(+), 2 deletions(-)
  create mode 100644 libavcodec/h266_parser.c

diff --git a/configure b/configure
index 90914752f1..77272948e3 100755
--- a/configure
+++ b/configure
@@ -2354,6 +2354,7 @@ CONFIG_EXTRA="
  cbs_av1
  cbs_h264
  cbs_h265
+cbs_h266
  cbs_jpeg
  cbs_mpeg2
  cbs_vp9
@@ -2622,6 +2623,7 @@ threads_if_any="$THREADS_LIST"
  cbs_av1_select="cbs"
  cbs_h264_select="cbs"
  cbs_h265_select="cbs"
+cbs_h266_select="cbs"


These two chunks belong to the previous patch adding cbs_h266. Otherwise 
CONFIG_CBS_H266 will not be defined for Makefile to use.



  cbs_jpeg_select="cbs"
  cbs_mpeg2_select="cbs"
  cbs_vp9_select="cbs"
@@ -3158,6 +3160,7 @@ av1_qsv_decoder_select="qsvdec"
  aac_parser_select="adts_header"
  av1_parser_select="cbs_av1"
  h264_parser_select="atsc_a53 golomb h264dsp h264parse"
+h266_parser_select="cbs_h266"
  hevc_parser_select="hevcparse"
  mpegaudio_parser_select="mpegaudioheader"
  mpegvideo_parser_select="mpegvideo"
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 4045c002b7..82cc9b8b93 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1098,6 +1098,7 @@ OBJS-$(CONFIG_GSM_PARSER)  += gsm_parser.o
  OBJS-$(CONFIG_H261_PARSER) += h261_parser.o
  OBJS-$(CONFIG_H263_PARSER) += h263_parser.o
  OBJS-$(CONFIG_H264_PARSER) += h264_parser.o h264_sei.o h264data.o
+OBJS-$(CONFIG_H266_PARSER) += h266_parser.o
  OBJS-$(CONFIG_HEVC_PARSER) += hevc_parser.o hevc_data.o
  OBJS-$(CONFIG_IPU_PARSER)  += ipu_parser.o
  OBJS-$(CONFIG_JPEG2000_PARSER) += jpeg2000_parser.o
diff --git a/libavcodec/h2645_parse.c b/libavcodec/h2645_parse.c
index 0f98b49fbe..2600371d3c 100644
--- a/libavcodec/h2645_parse.c
+++ b/libavcodec/h2645_parse.c


cbs_h266 needs the changes to this file you're adding here to split 
NALUs, so it should be done in a new separate patch applied before patch 
4/6.



@@ -29,6 +29,7 @@
  #include "bytestream.h"
  #include "hevc.h"
  #include "h264.h"
+#include "h266.h"
  #include "h2645_parse.h"
  
  int ff_h2645_extract_rbsp(const uint8_t *src, int length,

@@ -146,6 +147,47 @@ nsc:
  return si;
  }
  
+static const char *h266_nal_type_name[64] = {

+"TRAIL", //H266_NAL_TRAIL
+"STSA", //H266_NAL_STSA
+"RADL", //H266_NAL_RADL
+"RASL", //H266_NAL_RASL
+"RSV_VCL_4", //H266_NAL_RSV_VCL_4
+"RSV_VCL_5", //H266_NAL_RSV_VCL_5
+"RSV_VCL_6", //H266_NAL_RSV_VCL_6
+"IDR_W_RAD", //H266_NAL_IDR_W_RADL
+"IDR_N_LP", //H266_NAL_IDR_N_LP
+"CRA_NUT", //H266_NAL_CRA_NUT
+"GDR_NUT", //H266_NAL_GDR_NUT
+"RSV_IRAP_11", //H266_NAL_RSV_IRAP_11
+"OPI", //H266_NAL_OPI
+"DCI", //H266_NAL_DCI
+"VPS", //H266_NAL_VPS
+"SPS", //H266_NAL_SPS
+"PPS", //H266_NAL_PPS
+"PREFIX_AP", //H266_NAL_PREFIX_APS
+"SUFFIX_AP", //H266_NAL_SUFFIX_APS
+"PH", //H266_NAL_PH
+"AUD", //H266_NAL_AUD
+"EOS_NUT", //H266_NAL_EOS_NUT
+"EOB_NUT", //H266_NAL_EOB_NUT
+"PREFIX_SE", //H266_NAL_PREFIX_SEI
+"SUFFIX_SE", //H266_NAL_SUFFIX_SEI
+"FD_NUT", //H266_NAL_FD_NUT
+"RSV_NVCL_26", //H266_NAL_RSV_NVCL_26
+"RSV_NVCL_27", //H266_NAL_RSV_NVCL_27
+"UNSPEC_28", //H266_NAL_UNSPEC_28
+"UNSPEC_29", //H266_NAL_UNSPEC_29
+"UNSPEC_30", //H266_NAL_UNSPEC_30
+"UNSPEC_31", //H266_NAL_UNSPEC_31
+};
+
+static const char *h266_nal_unit_name(int nal_type)
+{
+av_assert0(nal_type >= 0 && nal_type < 32);
+return h266_nal_type_name[nal_type];
+}
+
  static const char *hevc_nal_type_name[64] = {
  "TRAIL_N", // HEVC_NAL_TRAIL_N
  "TRAIL_R", // HEVC_NAL_TRAIL_R
@@ -289,6 +331,32 @@ static int get_bit_length(H2645NAL *nal, int 
skip_trailing_zeros)
   * @return AVERROR_INVALIDDATA if the packet is not a valid NAL unit,
   * 0 otherwise
   */
+static int h266_parse_nal_header(H2645NAL *nal, void *logctx)
+{
+GetBitContext *gb = &nal->gb;
+
+if (get_bits1(gb) != 0) //forbidden_zero_bit
+return AVERROR_INVALIDDATA;
+
+if (get_bits1(gb) != 0) //nuh_reserved_zero_bit


This one should be ignored, otherwise bitstreams compliant with an 
hypotetical future revision of the spec that defines this bit will not 
work, when they should.



+return AVERROR_INVALIDDATA;
+
+nal->nuh_layer_id = get_bits(gb, 6);
+nal->type = get_bits(gb, 5);
+nal->temporal_id = get_bits(gb, 3) - 1;
+if (nal->temporal_id < 0)
+return AVERROR_INVALIDDATA;
+
+if ((nal->type >= H266_NAL_IDR_W_RADL && nal->type <= H266_NAL_RSV_IRAP_11) 
&& nal->temporal_id)
+return AVERROR_INVALIDDATA;
+
+av_log(logctx, AV_LOG_DEBUG,
+  "nal_unit_type: %d(%s), nuh_la

Re: [FFmpeg-devel] [PATCH 6/6] avcodec: add vvdec H.266/VVC decoder

2020-12-21 Thread Paul B Mahol
On Mon, Dec 21, 2020 at 7:08 AM Nuo Mi  wrote:

> you can download test clips here:
>
> https://www.itu.int/wftp3/av-arch/jvet-site/bitstream_exchange/VVC/under_test/VTM-11.0/
>
> 68.48% (163/238) clips are md5 matched with VTM 11:
>
> passed:
> 10b400_A_Bytedance_2.bit
> 10b400_B_Bytedance_2.bit
> 8b400_A_Bytedance_2.bit
> 8b400_B_Bytedance_2.bit
> 8b420_A_Bytedance_2.bit
> 8b420_B_Bytedance_2.bit
> ACTPIC_A_Huawei_3.bit
> ACTPIC_B_Huawei_3.bit
> ACTPIC_C_Huawei_3.bit
> AFF_A_HUAWEI_2.bit
> AFF_B_HUAWEI_2.bit
> ALF_A_Huawei_3.bit
> ALF_B_Huawei_3.bit
> ALF_C_KDDI_2.bit
> ALF_D_Qualcomm_2.bit
> AMVR_A_HHI_3.bit
> AMVR_B_HHI_3.bit
> APSALF_A_Qualcomm_2.bit
> APSLMCS_A_Dolby_3.bit
> APSLMCS_B_Dolby_3.bit
> APSLMCS_C_Dolby_2.bit
> APSMULT_A_MediaTek_3.bit
> APSMULT_B_MediaTek_3.bit
> AUD_A_Broadcom_3.bit
> BCW_A_MediaTek_3.bit
> BDOF_A_MediaTek_3.bit
> BDPCM_A_Orange_2.bit
> CCALF_A_Sharp_3.bit
> CCALF_B_Sharp_3.bit
> CCALF_C_Sharp_3.bit
> CCALF_D_Sharp_3.bit
> CCLM_A_KDDI_1.bit
> CIIP_A_MediaTek_3.bit
> CodingToolsSets_A_Tencent_2.bit
> CodingToolsSets_B_Tencent_2.bit
> CodingToolsSets_C_Tencent_2.bit
> CodingToolsSets_D_Tencent_2.bit
> CROP_A_Panasonic_3.bit
> CROP_B_Panasonic_4.bit
> CST_A_MediaTek_3.bit
> CTU_A_MediaTek_3.bit
> CTU_B_MediaTek_3.bit
> CTU_C_MediaTek_3.bit
> CUBEMAP_A_MediaTek_3.bit
> CUBEMAP_B_MediaTek_3.bit
> CUBEMAP_C_MediaTek_3.bit
> DEBLOCKING_A_Sharp_3.bit
> DEBLOCKING_B_Sharp_2.bit
> DEBLOCKING_C_Huawei_3.bit
> DEBLOCKING_E_Ericsson_2.bit
> DMVR_A_Huawei_3.bit
> DMVR_B_KDDI_3.bit
> DPB_A_Sharplabs_2.bit
> DPB_B_Sharplabs_2.bit
> DQ_A_HHI_3.bit
> ENT444HIGHTIER_A_Sony_3.bit
> ENT444HIGHTIER_B_Sony_3.bit
> ENT444HIGHTIER_C_Sony_3.bit
> ENT444HIGHTIER_D_Sony_3.bit
> ENT444MAINTIER_A_Sony_3.bit
> ENT444MAINTIER_B_Sony_3.bit
> ENT444MAINTIER_C_Sony_3.bit
> ENT444MAINTIER_D_Sony_3.bit
> ENTHIGHTIER_A_Sony_3.bit
> ENTHIGHTIER_B_Sony_3.bit
> ENTHIGHTIER_C_Sony_3.bit
> ENTHIGHTIER_D_Sony_3.bit
> ENTMAINTIER_A_Sony_3.bit
> ENTMAINTIER_B_Sony_3.bit
> ENTMAINTIER_C_Sony_3.bit
> ENTMAINTIER_D_Sony_3.bit
> ENTROPY_A_Chipsnmedia_2.bit
> ENTROPY_A_Qualcomm_2.bit
> ENTROPY_B_Sharp_2.bit
> ERP_A_MediaTek_3.bit
> FILLER_A_Bytedance_1.bit
> GPM_A_Alibaba_3.bit
> IBC_A_Tencent_2.bit
> IBC_B_Tencent_2.bit
> IBC_C_Tencent_2.bit
> IBC_D_Tencent_2.bit
> IP_B_Nokia_1.bit
> ISP_A_HHI_3.bit
> ISP_B_HHI_3.bit
> JCCR_A_Nokia_2.bit
> JCCR_B_Nokia_2.bit
> JCCR_C_HHI_3.bit
> JCCR_E_Nokia_1.bit
> JCCR_F_Nokia_1.bit
> LFNST_A_LGE_3.bit
> LFNST_B_LGE_3.bit
> LFNST_C_HHI_3.bit
> LMCS_A_Dolby_3.bit
> LOSSLESS_B_HHI_3.bit
> LTRP_A_ERICSSON_2.bit
> MERGE_A_Qualcomm_2.bit
> MERGE_B_Qualcomm_2.bit
> MERGE_C_Qualcomm_2.bit
> MERGE_D_Qualcomm_2.bit
> MERGE_E_Qualcomm_2.bit
> MERGE_F_Qualcomm_2.bit
> MERGE_G_Qualcomm_2.bit
> MERGE_H_Qualcomm_2.bit
> MERGE_I_Qualcomm_2.bit
> MERGE_J_Qualcomm_2.bit
> MIP_A_HHI_3.bit
> MIP_B_HHI_3.bit
> MPM_A_LGE_3.bit
> MRLP_A_HHI_2.bit
> MRLP_B_HHI_2.bit
> MTS_A_LGE_3.bit
> MTS_B_LGE_3.bit
> MTS_LFNST_A_LGE_3.bit
> MTS_LFNST_B_LGE_3.bit
> MVCOMP_A_Sharp_2.bit
> PDPC_A_Qualcomm_3.bit
> PDPC_B_Qualcomm_3.bit
> PDPC_C_Qualcomm_2.bit
> PHSH_B_Sharp_1.bit
> POC_A_Nokia_1.bit
> POUT_A_Sharplabs_2.bit
> PROF_A_Interdigital_3.bit
> PROF_B_Interdigital_3.bit
> QTBTT_A_MediaTek_3.bit
> QUANT_A_Huawei_2.bit
> QUANT_B_Huawei_2.bit
> QUANT_C_Huawei_2.bit
> RPL_A_ERICSSON_2.bit
> SAO_A_SAMSUNG_3.bit
> SAO_B_SAMSUNG_3.bit
> SAO_C_SAMSUNG_3.bit
> SbTMVP_A_Bytedance_3.bit
> SbTMVP_B_Bytedance_3.bit
> SBT_A_HUAWEI_2.bit
> SCALING_A_InterDigital_1.bit
> SCALING_B_InterDigital_1.bit
> SCALING_C_InterDigital_1.bit
> SDH_A_Dolby_2.bit
> SMVD_A_HUAWEI_2.bit
> TEMPSCAL_A_Panasonic_4.bit
> TEMPSCAL_C_Panasonic_3.bit
> TILE_A_Nokia_2.bit
> TILE_B_Nokia_2.bit
> TILE_C_Nokia_2.bit
> TILE_D_Nokia_2.bit
> TILE_E_Nokia_2.bit
> TILE_F_Nokia_2.bit
> TMVP_A_Chipsnmedia_3.bit
> TMVP_B_Chipsnmedia_3.bit
> TMVP_C_Chipsnmedia_3.bit
> TMVP_D_Chipsnmedia_3.bit
> TRANS_A_Chipsnmedia_2.bit
> TRANS_B_Chipsnmedia_2.bit
> TRANS_C_Chipsnmedia_2.bit
> TRANS_D_Chipsnmedia_2.bit
> WPP_A_Sharp_3.bit
> WPP_B_Sharp_2.bit
> WP_A_InterDigital_3.bit
> WP_B_InterDigital_3.bit
> WRAP_A_InterDigital_4.bit
> WRAP_B_InterDigital_4.bit
> WRAP_C_InterDigital_4.bit
> ---
>  configure   |   5 +-
>  libavcodec/Makefile |   1 +
>  libavcodec/allcodecs.c  |   1 +
>  libavcodec/libvvdec.cpp | 244 
>  4 files changed, 250 insertions(+), 1 deletion(-)
>  create mode 100644 libavcodec/libvvdec.cpp
>
> diff --git a/configure b/configure
> index 77272948e3..1e9a44db31 100755
> --- a/configure
> +++ b/configure
> @@ -285,6 +285,7 @@ External library support:
>--enable-libvorbis   enable Vorbis en/decoding via libvorbis,
> native implementation exists [no]
>--enable-libvpx  enable VP8 and VP9 de/encoding via libvpx [no]
> +  --enable-libvvdecenable VVC video encoding via libvvdec [no]
>

I do not think this one is correct.


>--enable-libwebp enab

Re: [FFmpeg-devel] [PATCH 7/8] avformat/aviobuf: Check for overflow in ffio_read_varlen()

2020-12-21 Thread Michael Niedermayer
On Mon, Dec 21, 2020 at 12:30:48PM +0100, Andreas Rheinhardt wrote:
> Michael Niedermayer:
> > No testcase
> > 
> > Signed-off-by: Michael Niedermayer 
> > ---
> >  libavformat/aviobuf.c | 2 ++
> >  1 file changed, 2 insertions(+)
> > 
> > diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c
> > index 78cc60b2ae..7730547106 100644
> > --- a/libavformat/aviobuf.c
> > +++ b/libavformat/aviobuf.c
> > @@ -917,6 +917,8 @@ uint64_t ffio_read_varlen(AVIOContext *bc){
> >  
> >  do{
> >  tmp = avio_r8(bc);
> > +if (val > UINT64_MAX>>7)
> > +return AVERROR_INVALIDDATA;
> >  val= (val<<7) + (tmp&127);
> >  }while(tmp&128);
> >  return val;
> > 
> The error can't be detected at all given that the function returns an
> uint64_t.

in practice the type of the destination matters.
But sure you are correct that this is not "great"
what do you suggest ? there are many ways to fix this
also the reuse of this function between demuxers feels not entirely
wise. Any change/fix must be reasonable for all demuxers, i imagine
that makes the mainaince for all harder ...

thx

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

The worst form of inequality is to try to make unequal things equal.
-- Aristotle


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

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

Re: [FFmpeg-devel] [PATCH 5/6] avcodec: add h266 parser

2020-12-21 Thread James Almer

On 12/21/2020 3:07 AM, Nuo Mi wrote:

---
  configure|   3 +
  libavcodec/Makefile  |   1 +
  libavcodec/h2645_parse.c |  73 +-
  libavcodec/h266_parser.c | 284 +++
  libavcodec/parsers.c |   1 +
  5 files changed, 360 insertions(+), 2 deletions(-)
  create mode 100644 libavcodec/h266_parser.c


[...]


+/**
+ * Parse NAL units of found picture and decode some basic information.
+ *
+ * @param s parser context.
+ * @param avctx codec context.
+ * @param buf buffer with field/frame data.
+ * @param buf_size size of the buffer.
+ */
+static int parse_nal_units(AVCodecParserContext *ctx, const uint8_t *buf,
+   int buf_size, AVCodecContext *avctx)
+{
+H266ParserContext *s = ctx->priv_data;
+CodedBitstreamFragment *pu = &s->picture_unit;
+CodedBitstreamH266Context *h266 = s->cbc->priv_data;
+const H266RawSPS *sps;
+const H266RawPPS *pps;
+const H266RawPH *ph;
+int ret, num = 0, den = 0;
+
+/* set some sane default values */
+ctx->pict_type = AV_PICTURE_TYPE_I;
+ctx->key_frame = 0;
+ctx->picture_structure = AV_PICTURE_STRUCTURE_FRAME;
+
+s->cbc->log_ctx = avctx;
+
+if (avctx->extradata_size && !s->parsed_extradata) {
+s->parsed_extradata = 1;
+
+if ((ret = ff_cbs_read(s->cbc, pu, avctx->extradata, 
avctx->extradata_size)) < 0)
+av_log(avctx, AV_LOG_WARNING, "Failed to parse extradata.\n");
+
+ff_cbs_fragment_reset(pu);
+}
+
+if ((ret = ff_cbs_read(s->cbc, pu, buf, buf_size))< 0) {
+av_log(avctx, AV_LOG_ERROR, "Failed to parse picture unit.\n");
+goto end;
+}
+
+sps = h266->active_sps;
+pps = h266->active_pps;
+ph = h266->active_ph;
+if (!h266->active_pps || !h266->active_ph) {
+av_log(avctx, AV_LOG_ERROR, "No pss or ph header available\n");
+goto end;
+}
+
+ctx->key_frame = ph->ph_gdr_or_irap_pic_flag;
+
+ctx->coded_width  = pps->pps_pic_width_in_luma_samples;
+ctx->coded_height = pps->pps_pic_height_in_luma_samples;
+ctx->width= pps->pps_pic_width_in_luma_samples  - 
pps->pps_conf_win_left_offset - pps->pps_conf_win_right_offset;
+ctx->height   = pps->pps_pic_height_in_luma_samples - 
pps->pps_conf_win_top_offset  - pps->pps_conf_win_bottom_offset;
+ctx->pict_type= get_pict_type(pu);
+ctx->format   = get_format(sps);
+avctx->profile  = sps->profile_tier_level.general_profile_idc;
+avctx->level= sps->profile_tier_level.general_level_idc;
+
+
+
+if(sps->sps_ptl_dpb_hrd_params_present_flag && 
sps->sps_timing_hrd_params_present_flag) {
+num = sps->sps_general_timing_hrd_parameters.num_units_in_tick;
+den = sps->sps_general_timing_hrd_parameters.time_scale;
+} else {
+av_log(avctx, AV_LOG_INFO, "No sps_timing_hrd_params_present_flag in sps, 
the fps may not right.\n");
+goto end;
+}
+if (num != 0 && den != 0)
+av_reduce(&avctx->framerate.den, &avctx->framerate.num,
+  num, den, 1 << 30);
+end:
+
+ff_cbs_fragment_reset(pu);
+s->cbc->log_ctx = NULL;
+return 0;
+}
+
+static int h266_parser_parse(AVCodecParserContext *s, AVCodecContext *avctx,
+  const uint8_t **poutbuf, int *poutbuf_size,
+  const uint8_t *buf, int buf_size)
+{
+int next;
+H266ParserContext *ctx = s->priv_data;
+ParseContext *pc = &ctx->pc;
+int is_dummy_buf = !buf_size;
+const uint8_t *dummy_buf = buf;
+
+if (avctx->extradata && !ctx->parsed_extradata) {
+av_log(avctx, AV_LOG_INFO, "extra data is not supported yet.\n");
+return AVERROR_PATCHWELCOME;


You're aborting here if extradata is present, but then check again in 
parse_nal_units() and actually try to parse it? Either parse it here or 
in parse_nal_units().


Judging by this check here, i assume in your tests you didn't handle 
streams with extradata, which is expected from raw bitstreams parsed by 
the demuxer you added in patch 3/6.
To workaround this, you need to add VVC support to the extract_extradata 
bitstream filter. It should be trivial to do.



+}
+
+if (s->flags & PARSER_FLAG_COMPLETE_FRAMES) {
+next = buf_size;
+} else {
+next = find_frame_end(s, buf, buf_size);
+if (ff_combine_frame(pc, next, &buf, &buf_size) < 0) {
+*poutbuf  = NULL;
+*poutbuf_size = 0;
+return buf_size;
+}
+}
+
+is_dummy_buf &= (dummy_buf == buf);
+
+if (!is_dummy_buf)
+parse_nal_units(s, buf, buf_size, avctx);
+
+*poutbuf  = buf;
+*poutbuf_size = buf_size;
+return next;
+
+}
+
+static const CodedBitstreamUnitType decompose_unit_types[] = {
+H266_NAL_TRAIL,
+H266_NAL_STSA,
+H266_NAL_RADL,
+H266_NAL_RASL,
+H266_NAL_IDR_W_RADL,
+H266_NAL_IDR_N_LP,
+H266_NAL_CRA_NUT,
+H266_NAL_GDR_NUT,
+ 

Re: [FFmpeg-devel] [PATCH 6/6] avcodec: add vvdec H.266/VVC decoder

2020-12-21 Thread chen
A little update
The sequence passed only 163 because they are not update their CMakeLists.txt.
I had been updated CMakeLists.txt and these patches in my github tree as well, 
I can found 81.93% (195/238) passed, 


Moreover, there have two of Field video clips, the decoder works, but output as 
separate of Top/Bottom Fields,
so the hash mismatch to VTM-11.0.


Overall, we can expect totally 82.77% (195+2/238) matched.


At 2020-12-22 01:40:43, "Paul B Mahol"  wrote:
>On Mon, Dec 21, 2020 at 7:08 AM Nuo Mi  wrote:
>
>> you can download test clips here:
>>
>> https://www.itu.int/wftp3/av-arch/jvet-site/bitstream_exchange/VVC/under_test/VTM-11.0/
>>
>> 68.48% (163/238) clips are md5 matched with VTM 11:
>>

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

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

Re: [FFmpeg-devel] [PATCH 4/8] avcodec/ffv1dec: Fix off by 1 error with quant tables

2020-12-21 Thread Paul B Mahol
Trivially ok

On Sat, Dec 19, 2020 at 1:42 AM Michael Niedermayer 
wrote:

> Fixes: assertion failure
> Fixes:
> 28447/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_FFV1_fuzzer-5369575948550144
>
> Found-by: continuous fuzzing process
> https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> Signed-off-by
> :
> Michael Niedermayer 
> ---
>  libavcodec/ffv1dec.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c
> index c704373cfe..0a3f425493 100644
> --- a/libavcodec/ffv1dec.c
> +++ b/libavcodec/ffv1dec.c
> @@ -786,7 +786,7 @@ static int read_header(FFV1Context *f)
>
>  if (f->version == 2) {
>  int idx = get_symbol(c, state, 0);
> -if (idx > (unsigned)f->quant_table_count) {
> +if (idx >= (unsigned)f->quant_table_count) {
>  av_log(f->avctx, AV_LOG_ERROR,
> "quant_table_index out of range\n");
>  return AVERROR_INVALIDDATA;
> --
> 2.17.1
>
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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

Re: [FFmpeg-devel] [PATCH 1/6] avcodec/h266: add shared header for h266

2020-12-21 Thread Mark Thompson

On 21/12/2020 06:07, Nuo Mi wrote:

---
  libavcodec/h266.h | 121 ++
  1 file changed, 121 insertions(+)
  create mode 100644 libavcodec/h266.h

diff --git a/libavcodec/h266.h b/libavcodec/h266.h
new file mode 100644
index 00..d5793b76fc
--- /dev/null
+++ b/libavcodec/h266.h
@@ -0,0 +1,121 @@
+/*
+ * H.266 shared code
+ *
+ * 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
+ */
+
+#ifndef AVCODEC_H266_H
+#define AVCODEC_H266_H
+
+/**
+ * Table 5 – NAL unit type codes and NAL unit type classes in
+ * T-REC-H.266-202008
+ */
+enum H266NALUnitType {


You don't use this type name anywhere.  I don't think there is any use in 
including it.


+H266_NAL_TRAIL   = 0,


Probably clearer as H266_NAL_UNIT_TYPE_FOO or H266_NUT_FOO?


+H266_NAL_STSA= 1,
+H266_NAL_RADL= 2,
+H266_NAL_RASL= 3,
+H266_NAL_RSV_VCL_4   = 4,
+H266_NAL_RSV_VCL_5   = 5,
+H266_NAL_RSV_VCL_6   = 6,
+H266_NAL_IDR_W_RADL  = 7,
+H266_NAL_IDR_N_LP= 8,
+H266_NAL_CRA_NUT = 9,
+H266_NAL_GDR_NUT = 10,
+H266_NAL_RSV_IRAP_11 = 11,
+H266_NAL_OPI = 12,
+H266_NAL_DCI = 13,
+H266_NAL_VPS = 14,
+H266_NAL_SPS = 15,
+H266_NAL_PPS = 16,
+H266_NAL_PREFIX_APS  = 17,
+H266_NAL_SUFFIX_APS  = 18,
+H266_NAL_PH  = 19,
+H266_NAL_AUD = 20,
+H266_NAL_EOS_NUT = 21,
+H266_NAL_EOB_NUT = 22,


The redundant _NUT suffixes are inconsistent.


+H266_NAL_PREFIX_SEI  = 23,
+H266_NAL_SUFFIX_SEI  = 24,
+H266_NAL_FD_NUT  = 25,
+H266_NAL_RSV_NVCL_26 = 26,
+H266_NAL_RSV_NVCL_27 = 27,
+H266_NAL_UNSPEC_28   = 28,
+H266_NAL_UNSPEC_29   = 29,
+H266_NAL_UNSPEC_30   = 30,
+H266_NAL_UNSPEC_31   = 31,
+};
+
+enum H266SliceType {


This type name too.


+H266_SLICE_B = 0,


H266_SLICE_TYPE_B


+H266_SLICE_P = 1,
+H266_SLICE_I = 2,
+};
+
+enum {
+H266_MAX_PLANES = 3,
+//7.4.3.3 The value of vps_max_sublayers_minus1 shall be in the range of 0 
to 6, inclusive
+H266_MAX_SUB_LAYERS = 7,
+
+// 7.3.2.3: vps_video_parameter_set_id is u(4).
+H266_MAX_VPS_COUNT = 16,
+// 7.3.2.4: sps_seq_parameter_set_id is in [0, 15].


It's u(4), not a stated constraint.  (Unlike in H.264, where these ids very 
ue(v) with a constraint in the text.)


+H266_MAX_SPS_COUNT = 16,
+// 7.3.2.5: pps_pic_parameter_set_id is in [0, 63].


u(6)


+H266_MAX_PPS_COUNT = 64,
+
+// A.4.2: MaxDpbSize is bounded above by 16.


The definition in terms of maxDpbPicBuf is clearer than it was in H.265, so I 
think say that rather than just the result.


+H266_MAX_DPB_SIZE = 16,
+
+//7.4.3.4 sps_num_ref_pic_lists in range [0, 64]
+H266_MAX_REF_PIC_LISTS = 64,
+
+//7.4.3.3 sps_num_points_in_qp_table_minus1[i] in range [0, 36 − 
sps_qp_table_start_minus26[i]],
+//sps_qp_table_start_minus26[i] in range [sps_qp_table_start_minus26[i] 
−26 − QpBdOffset, 36]
+//for 10 bitsQpBdOffset is 12, so sps_num_points_in_qp_table_minus1[i] in 
range [0, 74]
+H266_MAX_POINTS_IN_QP_TABLE = 75,
+
+// 7.4.6.1: hrd_cpb_cnt_minus1 is in [0, 31].
+H266_MAX_CPB_CNT = 32,
+
+// A.4.1: in table A.6 the highest level allows a MaxLumaPs of 35 651 584.


Table A.1 is the reference for MaxLumaPs.  (Table A.6 is only informative, 
though this value does appear for 8K.)


+H266_MAX_LUMA_PS = 35651584,
+// A.4.1: pic_width_in_luma_samples and pic_height_in_luma_samples are
+// constrained to be not greater than sqrt(MaxLumaPs * 8).  Hence height/
+// width are bounded above by sqrt(8 * 35651584) = 16888.2 samples.
+H266_MAX_WIDTH  = 16888,
+H266_MAX_HEIGHT = 16888,
+
+// A.4.1: table A.1 allows at most 20 tile rows for any level.


No it doesn't?  I don't see any reference to tile rows in table A.1.


+H266_MAX_TILE_ROWS= 20, > +// A.4.1: table A.1 allows at most 20 
tile columns for any level.
+H266_MAX_TILE_COLUMNS = 20,
+
+// A.4.1 table A.1 allows at most 600 slice for any level.
+H266_MAX_SLICES = 600,
+
+// 7.4.8: in the worst case (tiles_enabled_flag and
+// entropy_coding_sync_enabled_flag are both set), entry points can be
+   

Re: [FFmpeg-devel] [PATCH 1/6] avcodec/h266: add shared header for h266

2020-12-21 Thread James Almer

On 12/21/2020 5:42 PM, Mark Thompson wrote:

On 21/12/2020 06:07, Nuo Mi wrote:

---
  libavcodec/h266.h | 121 ++
  1 file changed, 121 insertions(+)
  create mode 100644 libavcodec/h266.h

diff --git a/libavcodec/h266.h b/libavcodec/h266.h
new file mode 100644
index 00..d5793b76fc
--- /dev/null
+++ b/libavcodec/h266.h
@@ -0,0 +1,121 @@
+/*
+ * H.266 shared code
+ *
+ * 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

+ */
+
+#ifndef AVCODEC_H266_H
+#define AVCODEC_H266_H
+
+/**
+ * Table 5 – NAL unit type codes and NAL unit type classes in
+ * T-REC-H.266-202008
+ */
+enum H266NALUnitType {


You don't use this type name anywhere.  I don't think there is any use 
in including it.


It can be used at some point down the line.

hevcdec for example names its enum and then uses it when it takes it as 
input argument in ff_hevc_nal_is_nonref().





+    H266_NAL_TRAIL   = 0,


Probably clearer as H266_NAL_UNIT_TYPE_FOO or H266_NUT_FOO?


The way he named them is consistent with H264 and HEVC defines, so i'm 
inclined to leave it this way.





+    H266_NAL_STSA    = 1,
+    H266_NAL_RADL    = 2,
+    H266_NAL_RASL    = 3,
+    H266_NAL_RSV_VCL_4   = 4,
+    H266_NAL_RSV_VCL_5   = 5,
+    H266_NAL_RSV_VCL_6   = 6,
+    H266_NAL_IDR_W_RADL  = 7,
+    H266_NAL_IDR_N_LP    = 8,
+    H266_NAL_CRA_NUT = 9,
+    H266_NAL_GDR_NUT = 10,
+    H266_NAL_RSV_IRAP_11 = 11,
+    H266_NAL_OPI = 12,
+    H266_NAL_DCI = 13,
+    H266_NAL_VPS = 14,
+    H266_NAL_SPS = 15,
+    H266_NAL_PPS = 16,
+    H266_NAL_PREFIX_APS  = 17,
+    H266_NAL_SUFFIX_APS  = 18,
+    H266_NAL_PH  = 19,
+    H266_NAL_AUD = 20,
+    H266_NAL_EOS_NUT = 21,
+    H266_NAL_EOB_NUT = 22,


The redundant _NUT suffixes are inconsistent.


Changing this one i'm ok with.




+    H266_NAL_PREFIX_SEI  = 23,
+    H266_NAL_SUFFIX_SEI  = 24,
+    H266_NAL_FD_NUT  = 25,
+    H266_NAL_RSV_NVCL_26 = 26,
+    H266_NAL_RSV_NVCL_27 = 27,
+    H266_NAL_UNSPEC_28   = 28,
+    H266_NAL_UNSPEC_29   = 29,
+    H266_NAL_UNSPEC_30   = 30,
+    H266_NAL_UNSPEC_31   = 31,
+};
+
+enum H266SliceType {


This type name too.


+    H266_SLICE_B = 0,


H266_SLICE_TYPE_B


+    H266_SLICE_P = 1,
+    H266_SLICE_I = 2,
+};
+
+enum {
+    H266_MAX_PLANES = 3,
+    //7.4.3.3 The value of vps_max_sublayers_minus1 shall be in the 
range of 0 to 6, inclusive

+    H266_MAX_SUB_LAYERS = 7,
+
+    // 7.3.2.3: vps_video_parameter_set_id is u(4).
+    H266_MAX_VPS_COUNT = 16,
+    // 7.3.2.4: sps_seq_parameter_set_id is in [0, 15].


It's u(4), not a stated constraint.  (Unlike in H.264, where these ids 
very ue(v) with a constraint in the text.)



+    H266_MAX_SPS_COUNT = 16,
+    // 7.3.2.5: pps_pic_parameter_set_id is in [0, 63].


u(6)


+    H266_MAX_PPS_COUNT = 64,
+
+    // A.4.2: MaxDpbSize is bounded above by 16.


The definition in terms of maxDpbPicBuf is clearer than it was in H.265, 
so I think say that rather than just the result.



+    H266_MAX_DPB_SIZE = 16,
+
+    //7.4.3.4 sps_num_ref_pic_lists in range [0, 64]
+    H266_MAX_REF_PIC_LISTS = 64,
+
+    //7.4.3.3 sps_num_points_in_qp_table_minus1[i] in range [0, 36 − 
sps_qp_table_start_minus26[i]],
+    //sps_qp_table_start_minus26[i] in range 
[sps_qp_table_start_minus26[i] −26 − QpBdOffset, 36]
+    //for 10 bitsQpBdOffset is 12, so 
sps_num_points_in_qp_table_minus1[i] in range [0, 74]

+    H266_MAX_POINTS_IN_QP_TABLE = 75,
+
+    // 7.4.6.1: hrd_cpb_cnt_minus1 is in [0, 31].
+    H266_MAX_CPB_CNT = 32,
+
+    // A.4.1: in table A.6 the highest level allows a MaxLumaPs of 35 
651 584.


Table A.1 is the reference for MaxLumaPs.  (Table A.6 is only 
informative, though this value does appear for 8K.)



+    H266_MAX_LUMA_PS = 35651584,
+    // A.4.1: pic_width_in_luma_samples and 
pic_height_in_luma_samples are
+    // constrained to be not greater than sqrt(MaxLumaPs * 8).  Hence 
height/

+    // width are bounded above by sqrt(8 * 35651584) = 16888.2 samples.
+    H266_MAX_WIDTH  = 16888,
+    H266_MAX_HEIGHT = 16888,
+
+    // A.4.1: table A.1 allows at most 20 tile rows for any level.


No it doesn't?  I don't see any reference to tile rows in table A.1.

+    H266

Re: [FFmpeg-devel] [PATCH 2/8] avformat/mpegts: simplify nb_packets code

2020-12-21 Thread Michael Niedermayer
On Sun, Dec 20, 2020 at 11:30:05PM +0100, Marton Balint wrote:
> 
> 
> On Sat, 19 Dec 2020, Michael Niedermayer wrote:
> 
> > Signed-off-by: Michael Niedermayer 
> > ---
> > libavformat/mpegts.c | 7 ++-
> > 1 file changed, 2 insertions(+), 5 deletions(-)
> > 
> > diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c
> > index 1122455f66..cc292ab929 100644
> > --- a/libavformat/mpegts.c
> > +++ b/libavformat/mpegts.c
> > @@ -3090,7 +3090,6 @@ static int mpegts_read_header(AVFormatContext *s)
> > AVStream *st;
> > int pcr_pid, pid, nb_packets, nb_pcrs, ret, pcr_l;
> > int64_t pcrs[2], pcr_h;
> > -int packet_count[2];
> > uint8_t packet[TS_PACKET_SIZE];
> > const uint8_t *data;
> > 
> > @@ -3116,7 +3115,6 @@ static int mpegts_read_header(AVFormatContext *s)
> > parse_pcr(&pcr_h, &pcr_l, data) == 0) {
> > finished_reading_packet(s, ts->raw_packet_size);
> > pcr_pid = pid;
> > -packet_count[nb_pcrs] = nb_packets;
> > pcrs[nb_pcrs] = pcr_h * 300 + pcr_l;
> > nb_pcrs++;
> > if (nb_pcrs >= 2) {
> > @@ -3126,7 +3124,6 @@ static int mpegts_read_header(AVFormatContext *s)
> > } else {
> > av_log(ts->stream, AV_LOG_WARNING, "invalid pcr 
> > pair %"PRId64" >= %"PRId64"\n", pcrs[0], pcrs[1]);
> > pcrs[0] = pcrs[1];
> > -packet_count[0] = packet_count[1];
> > nb_pcrs--;
> > }
> > }
> > @@ -3138,8 +3135,8 @@ static int mpegts_read_header(AVFormatContext *s)
> > 
> > /* NOTE1: the bitrate is computed without the FEC */
> > /* NOTE2: it is only the bitrate of the start of the stream */
> > -ts->pcr_incr = (pcrs[1] - pcrs[0]) / (packet_count[1] - 
> > packet_count[0]);
> > -ts->cur_pcr  = pcrs[0] - ts->pcr_incr * packet_count[0];
> > +ts->pcr_incr = pcrs[1] - pcrs[0];
> > +ts->cur_pcr  = pcrs[0] - ts->pcr_incr * (nb_packets - 1);
> > s->bit_rate  = TS_PACKET_SIZE * 8 * 2700LL / ts->pcr_incr;
> > st->codecpar->bit_rate = s->bit_rate;
> > st->start_time  = ts->cur_pcr;
> 
> LGTM for this and the preivous as well.

will apply


> 
> (BTW did anybody hear of anyone ever using the mpegts raw demuxer?)

it seems its not tested by fate

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

No snowflake in an avalanche ever feels responsible. -- Voltaire


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

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

Re: [FFmpeg-devel] [PATCH 4/8] avcodec/ffv1dec: Fix off by 1 error with quant tables

2020-12-21 Thread Michael Niedermayer
On Mon, Dec 21, 2020 at 08:44:33PM +0100, Paul B Mahol wrote:
> Trivially ok

will apply

thx

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

Awnsering whenever a program halts or runs forever is
On a turing machine, in general impossible (turings halting problem).
On any real computer, always possible as a real computer has a finite number
of states N, and will either halt in less than N cycles or never halt.


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

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

Re: [FFmpeg-devel] [PATCH v3] avcodec/libvpxenc: add a way to set VP9E_SET_SVC_REF_FRAME_CONFIG

2020-12-21 Thread James Zern
On Thu, Dec 17, 2020 at 2:43 PM Wonkap Jang  wrote:
>
>
>
> On Thu, Dec 17, 2020 at 10:48 AM James Zern  wrote:
>>
>> On Tue, Dec 15, 2020 at 9:24 AM Wonkap Jang  wrote:
>> >
>> > Hi James
>> >
>> > On Tue, Dec 15, 2020 at 9:18 AM Wonkap Jang  wrote:
>> >>
>> >> In order to fine-control referencing schemes in VP9 encoding, there
>> >> is a need to use VP9E_SET_SVC_REF_FRAME_CONFIG method. This commit
>> >> provides a way to use the API through frame metadata.
>> >> ---
>> >>  doc/encoders.texi  | 32 +
>> >>  libavcodec/libvpxenc.c | 81 ++
>> >>  2 files changed, 113 insertions(+)
>> >>
>> > [...]
>> > In reply to your comment about using ABI_VERSION for guarding the changes, 
>> > the reason I used the unrelated   
>> > "VPX_CTRL_VP9E_SET_MAX_INTER_BITRATE_PCT" is because the ABI_VERION did 
>> > not seem to have changed between the last commit that you suggested 
>> > (v1.7.0-936-g04b3d49ba) to use and the lateset libvpx version. Can you 
>> > confirm this?
>> >
>>
>> I think I may have mentioned, this doesn't have to be precise. You can
>> just make 1.8.0 the baseline.
>> Also it looks like you might have some syntax errors in encoders.texi.
>> If you have the prerequisites, make doc can test the file locally.
>> https://patchwork.ffmpeg.org/project/ffmpeg/patch/20201215171825.2598712-1-won...@google.com/
>
>
> Hi James,
>
> Maybe my local setup has outdated codebase for the doc changes...weird 
> because it is building without any problems... I even checked it with 
> "texi2html" tool.
> I'll try to fix the doc compile issue. But, I don't quite get what you mean 
> by  "just make 1.8.0 the baseline".
> What I was trying to get to was the fact that you wanted me to use 
> VPX_ENCODER_ABI_VERSION instead of VPX_CTRL_VP9E_SET_MAX_INTER_BITRATE_PCT.
> But, what I see is that VPX_ENCODER_ABI_VERSION has not changed even in the 
> latest codebase. Are you suggesting something else by saying "just make 1.8.0 
> the baseline"?
> Is there something I am missing? :)
>

It's possible I misread your earlier replies. I see what you mean, the
abi version hasn't changed at all since then, though it should have.
It will change in the next release, but this check is ok. We have some
similar variants already.

> Let me know,
>
> Thanks!!
>
> Wonkap
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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

Re: [FFmpeg-devel] [PATCH v3] avcodec/libvpxenc: add a way to set VP9E_SET_SVC_REF_FRAME_CONFIG

2020-12-21 Thread Wonkap Jang
On Mon, Dec 21, 2020 at 1:40 PM James Zern  wrote:

> On Thu, Dec 17, 2020 at 2:43 PM Wonkap Jang  wrote:
> >
> >
> >
> > On Thu, Dec 17, 2020 at 10:48 AM James Zern  wrote:
> >>
> >> On Tue, Dec 15, 2020 at 9:24 AM Wonkap Jang  wrote:
> >> >
> >> > Hi James
> >> >
> >> > On Tue, Dec 15, 2020 at 9:18 AM Wonkap Jang 
> wrote:
> >> >>
> >> >> In order to fine-control referencing schemes in VP9 encoding, there
> >> >> is a need to use VP9E_SET_SVC_REF_FRAME_CONFIG method. This commit
> >> >> provides a way to use the API through frame metadata.
> >> >> ---
> >> >>  doc/encoders.texi  | 32 +
> >> >>  libavcodec/libvpxenc.c | 81
> ++
> >> >>  2 files changed, 113 insertions(+)
> >> >>
> >> > [...]
> >> > In reply to your comment about using ABI_VERSION for guarding the
> changes, the reason I used the unrelated
>  "VPX_CTRL_VP9E_SET_MAX_INTER_BITRATE_PCT" is because the ABI_VERION did
> not seem to have changed between the last commit that you suggested
> (v1.7.0-936-g04b3d49ba) to use and the lateset libvpx version. Can you
> confirm this?
> >> >
> >>
> >> I think I may have mentioned, this doesn't have to be precise. You can
> >> just make 1.8.0 the baseline.
> >> Also it looks like you might have some syntax errors in encoders.texi.
> >> If you have the prerequisites, make doc can test the file locally.
> >>
> https://patchwork.ffmpeg.org/project/ffmpeg/patch/20201215171825.2598712-1-won...@google.com/
> >
> >
> > Hi James,
> >
> > Maybe my local setup has outdated codebase for the doc changes...weird
> because it is building without any problems... I even checked it with
> "texi2html" tool.
> > I'll try to fix the doc compile issue. But, I don't quite get what you
> mean by  "just make 1.8.0 the baseline".
> > What I was trying to get to was the fact that you wanted me to use
> VPX_ENCODER_ABI_VERSION instead of VPX_CTRL_VP9E_SET_MAX_INTER_BITRATE_PCT.
> > But, what I see is that VPX_ENCODER_ABI_VERSION has not changed even in
> the latest codebase. Are you suggesting something else by saying "just make
> 1.8.0 the baseline"?
> > Is there something I am missing? :)
> >
>
> It's possible I misread your earlier replies. I see what you mean, the
> abi version hasn't changed at all since then, though it should have.
> It will change in the next release, but this check is ok. We have some
> similar variants already.
>
> > Let me know,
> >
> > Thanks!!
> >
> > Wonkap
>

OK. then, I'll send out new changes. with updated code base.

Thanks,

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

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

Re: [FFmpeg-devel] [PATCH 14/39] avcodec/h261dec: Don't use too big max_depth in get_vlc2()

2020-12-21 Thread Michael Niedermayer
On Mon, Dec 21, 2020 at 12:57:17PM +0100, Andreas Rheinhardt wrote:
> Michael Niedermayer:
> > On Thu, Dec 10, 2020 at 12:16:32PM +0100, Andreas Rheinhardt wrote:
> >> Signed-off-by: Andreas Rheinhardt 
> >> ---
> >>  libavcodec/h261dec.c | 2 +-
> >>  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > ok assuming its not better to make H261_CBP_VLC_BITS smaller
> > 
> > thx
> > 
> > [...]
> > 
> Honestly, I don't care either way. Do you have a preference?

no preference, apply what you prefer

thx

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

Whats the most studid thing your enemy could do ? Blow himself up
Whats the most studid thing you could do ? Give up your rights and
freedom because your enemy blew himself up.



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

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

Re: [FFmpeg-devel] [PATCH 4/6] avcodec: add cbs for h266

2020-12-21 Thread Mark Thompson

On 21/12/2020 06:07, Nuo Mi wrote:

---
  libavcodec/Makefile   |1 +
  libavcodec/cbs.c  |6 +
  libavcodec/cbs_h2645.c|  337 ++
  libavcodec/cbs_h266.h |  711 
  libavcodec/cbs_h266_syntax_template.c | 1493 +
  libavcodec/cbs_internal.h |1 +
  6 files changed, 2549 insertions(+)
  create mode 100644 libavcodec/cbs_h266.h
  create mode 100644 libavcodec/cbs_h266_syntax_template.c

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 450781886d..4045c002b7 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -73,6 +73,7 @@ OBJS-$(CONFIG_CBS) += cbs.o
  OBJS-$(CONFIG_CBS_AV1) += cbs_av1.o
  OBJS-$(CONFIG_CBS_H264)+= cbs_h2645.o h2645_parse.o
  OBJS-$(CONFIG_CBS_H265)+= cbs_h2645.o h2645_parse.o
+OBJS-$(CONFIG_CBS_H266)+= cbs_h2645.o h2645_parse.o
  OBJS-$(CONFIG_CBS_JPEG)+= cbs_jpeg.o
  OBJS-$(CONFIG_CBS_MPEG2)   += cbs_mpeg2.o
  OBJS-$(CONFIG_CBS_VP9) += cbs_vp9.o
diff --git a/libavcodec/cbs.c b/libavcodec/cbs.c
index f98531e131..2b4f3b2bea 100644
--- a/libavcodec/cbs.c
+++ b/libavcodec/cbs.c
@@ -38,6 +38,9 @@ static const CodedBitstreamType *cbs_type_table[] = {
  #if CONFIG_CBS_H265
  &ff_cbs_type_h265,
  #endif
+#if CONFIG_CBS_H266
+&ff_cbs_type_h266,
+#endif
  #if CONFIG_CBS_JPEG
  &ff_cbs_type_jpeg,
  #endif
@@ -59,6 +62,9 @@ const enum AVCodecID ff_cbs_all_codec_ids[] = {
  #if CONFIG_CBS_H265
  AV_CODEC_ID_H265,
  #endif
+#if CONFIG_CBS_H266
+AV_CODEC_ID_H266,
+#endif
  #if CONFIG_CBS_JPEG
  AV_CODEC_ID_MJPEG,
  #endif
diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c
index 434322492c..0b884c1ed0 100644
--- a/libavcodec/cbs_h2645.c
+++ b/libavcodec/cbs_h2645.c
@@ -24,11 +24,13 @@
  #include "cbs_internal.h"
  #include "cbs_h264.h"
  #include "cbs_h265.h"
+#include "cbs_h266.h"
  #include "h264.h"
  #include "h264_sei.h"
  #include "h2645_parse.h"
  #include "hevc.h"
  #include "hevc_sei.h"
+#include "h266.h"
  
  
  static int cbs_read_ue_golomb(CodedBitstreamContext *ctx, GetBitContext *gbc,

@@ -256,6 +258,7 @@ static int cbs_h265_payload_extension_present(GetBitContext 
*gbc, uint32_t paylo
  #define FUNC_NAME(rw, codec, name) cbs_ ## codec ## _ ## rw ## _ ## name
  #define FUNC_H264(rw, name) FUNC_NAME(rw, h264, name)
  #define FUNC_H265(rw, name) FUNC_NAME(rw, h265, name)
+#define FUNC_H266(rw, name) FUNC_NAME(rw, h266, name)
  
  #define SUBSCRIPTS(subs, ...) (subs > 0 ? ((int[subs + 1]){ subs, __VA_ARGS__ }) : NULL)
  
@@ -364,6 +367,10 @@ static int cbs_h2645_read_more_rbsp_data(GetBitContext *gbc)

  #include "cbs_h265_syntax_template.c"
  #undef FUNC
  
+#define FUNC(name) FUNC_H266(READWRITE, name)

+#include "cbs_h266_syntax_template.c"
+#undef FUNC
+
  #undef READ
  #undef READWRITE
  #undef RWContext


Please include the second time for write support as well.  (With only read this 
is incredibly hard to test.)


@@ -679,6 +686,9 @@ cbs_h2645_replace_ps(4, PPS, pps, pic_parameter_set_id)
  cbs_h2645_replace_ps(5, VPS, vps, vps_video_parameter_set_id)
  cbs_h2645_replace_ps(5, SPS, sps, sps_seq_parameter_set_id)
  cbs_h2645_replace_ps(5, PPS, pps, pps_pic_parameter_set_id)
+cbs_h2645_replace_ps(6, VPS, vps, vps_video_parameter_set_id)
+cbs_h2645_replace_ps(6, SPS, sps, sps_seq_parameter_set_id)
+cbs_h2645_replace_ps(6, PPS, pps, pps_pic_parameter_set_id)
  
  static int cbs_h264_read_nal_unit(CodedBitstreamContext *ctx,

CodedBitstreamUnit *unit)
@@ -920,6 +930,117 @@ static int cbs_h265_read_nal_unit(CodedBitstreamContext 
*ctx,
  return 0;
  }
  
+static int cbs_h266_read_nal_unit(CodedBitstreamContext *ctx,

+  CodedBitstreamUnit *unit)
+{
+GetBitContext gbc;
+int err;
+
+err = init_get_bits(&gbc, unit->data, 8 * unit->data_size);


init_get_bits8()


+if (err < 0)
+return err;
+
+err = ff_cbs_alloc_unit_content2(ctx, unit);
+if (err < 0)
+return err;
+
+switch (unit->type) {
+case H266_NAL_VPS:
+{
+H266RawVPS *vps = unit->content;
+
+err = cbs_h266_read_vps(ctx, &gbc, vps);


This isn't implemented, so don't include it here so it returns ENOSYS.


+if (err < 0)
+return err;
+
+err = cbs_h266_replace_vps(ctx, unit);
+if (err < 0)
+return err;
+}
+break;
+case H266_NAL_SPS:
+{
+H266RawSPS *sps = unit->content;
+
+err = cbs_h266_read_sps(ctx, &gbc, sps);
+if (err < 0)
+return err;
+
+err = cbs_h266_replace_sps(ctx, unit);
+if (err < 0)
+return err;
+}
+break;
+
+case H266_NAL_PPS:
+{
+H266RawPPS *pps = unit->

Re: [FFmpeg-devel] [PATCH 1/2] ffmpeg: add option stats_period

2020-12-21 Thread Michael Niedermayer
On Mon, Dec 21, 2020 at 02:51:20PM +0530, Gyan Doshi wrote:
> At present, progress stats are updated at a hardcoded interval of
> half a second. For long processes, this can lead to bloated
> logs and progress reports.
> 
> Users can now set a custom period using option -stats_period
> Default is kept at 0.5 seconds.
> ---
>  doc/ffmpeg.texi  |  7 ++-
>  fftools/ffmpeg.c |  2 +-
>  fftools/ffmpeg.h |  1 +
>  fftools/ffmpeg_opt.c | 18 ++
>  4 files changed, 26 insertions(+), 2 deletions(-)

probably ok

thx

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

"I am not trying to be anyone's saviour, I'm trying to think about the
 future and not be sad" - Elon Musk



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

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

[FFmpeg-devel] [PATCH] avformat: add mpegtsraw muxer

2020-12-21 Thread Aman Karmani
From: Aman Karmani 

Allows easier writing of a AV_CODEC_ID_MPEG2TS stream out to disk.

Signed-off-by: Aman Karmani 
---
 libavformat/Makefile |  1 +
 libavformat/allformats.c |  1 +
 libavformat/rawenc.c | 14 ++
 3 files changed, 16 insertions(+)

diff --git a/libavformat/Makefile b/libavformat/Makefile
index 97d868081b..ad528de589 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -350,6 +350,7 @@ OBJS-$(CONFIG_MPEG2VOB_MUXER)+= mpegenc.o
 OBJS-$(CONFIG_MPEGPS_DEMUXER)+= mpeg.o
 OBJS-$(CONFIG_MPEGTS_DEMUXER)+= mpegts.o
 OBJS-$(CONFIG_MPEGTS_MUXER)  += mpegtsenc.o
+OBJS-$(CONFIG_MPEGTSRAW_MUXER)   += rawenc.o
 OBJS-$(CONFIG_MPEGVIDEO_DEMUXER) += mpegvideodec.o rawdec.o
 OBJS-$(CONFIG_MPJPEG_DEMUXER)+= mpjpegdec.o
 OBJS-$(CONFIG_MPJPEG_MUXER)  += mpjpeg.o
diff --git a/libavformat/allformats.c b/libavformat/allformats.c
index 0e0caaad39..6106344ba0 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -279,6 +279,7 @@ extern AVInputFormat  ff_mpegps_demuxer;
 extern AVInputFormat  ff_mpegts_demuxer;
 extern AVOutputFormat ff_mpegts_muxer;
 extern AVInputFormat  ff_mpegtsraw_demuxer;
+extern AVOutputFormat ff_mpegtsraw_muxer;
 extern AVInputFormat  ff_mpegvideo_demuxer;
 extern AVInputFormat  ff_mpjpeg_demuxer;
 extern AVOutputFormat ff_mpjpeg_muxer;
diff --git a/libavformat/rawenc.c b/libavformat/rawenc.c
index 32704f9bfd..38def493cf 100644
--- a/libavformat/rawenc.c
+++ b/libavformat/rawenc.c
@@ -465,6 +465,20 @@ AVOutputFormat ff_mpeg2video_muxer = {
 };
 #endif
 
+#if CONFIG_MPEGTSRAW_MUXER
+AVOutputFormat ff_mpegtsraw_muxer = {
+.name   = "mpegtsraw",
+.long_name  = NULL_IF_CONFIG_SMALL("raw MPEG-TS"),
+.mime_type  = "video/MP2T",
+.extensions = "ts,m2t,m2ts,mts",
+.audio_codec= AV_CODEC_ID_NONE,
+.video_codec= AV_CODEC_ID_NONE,
+.data_codec = AV_CODEC_ID_MPEG2TS,
+.write_packet   = ff_raw_write_packet,
+.flags  = AVFMT_NOTIMESTAMPS,
+};
+#endif
+
 #if CONFIG_RAWVIDEO_MUXER
 AVOutputFormat ff_rawvideo_muxer = {
 .name  = "rawvideo",
-- 
2.29.2

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

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

Re: [FFmpeg-devel] [PATCH] libswscale: avoid UB nullptr-with-offset.

2020-12-21 Thread Michael Niedermayer
On Mon, Dec 21, 2020 at 01:52:08PM +, jleconte wrote:
> ---
>  libswscale/slice.c| 12 +---
>  libswscale/swscale_unscaled.c |  5 +++--
>  2 files changed, 8 insertions(+), 9 deletions(-)
> 
> diff --git a/libswscale/slice.c b/libswscale/slice.c
> index 7849b70f4d..b1cfc0e506 100644
> --- a/libswscale/slice.c
> +++ b/libswscale/slice.c
> @@ -158,14 +158,12 @@ int ff_init_slice_from_src(SwsSlice * s, uint8_t 
> *src[4], int stride[4], int src
>  chrY + chrH,
>  lumY + lumH};
>  
> -uint8_t *const src_[4] = {src[0] + (relative ? 0 : start[0]) * stride[0],
> -  src[1] + (relative ? 0 : start[1]) * stride[1],
> -  src[2] + (relative ? 0 : start[2]) * stride[2],
> -  src[3] + (relative ? 0 : start[3]) * 
> stride[3]};
> -
>  s->width = srcW;
>  
>  for (i = 0; i < 4; ++i) {
> +if (!src[i])
> +  continue;

indention


> +uint8_t *const src_ = src[i] + (relative ? 0 : start[i]) * stride[i];

please call this src_i, its more clear then what it is


>  int j;
>  int first = s->plane[i].sliceY;
>  int n = s->plane[i].available_lines;
> @@ -175,13 +173,13 @@ int ff_init_slice_from_src(SwsSlice * s, uint8_t 
> *src[4], int stride[4], int src
>  if (start[i] >= first && n >= tot_lines) {
>  s->plane[i].sliceH = FFMAX(tot_lines, s->plane[i].sliceH);
>  for (j = 0; j < lines; j+= 1)
> -s->plane[i].line[start[i] - first + j] = src_[i] +  j * 
> stride[i];
> +s->plane[i].line[start[i] - first + j] = src_ +  j * 
> stride[i];
>  } else {
>  s->plane[i].sliceY = start[i];
>  lines = lines > n ? n : lines;
>  s->plane[i].sliceH = lines;
>  for (j = 0; j < lines; j+= 1)
> -s->plane[i].line[j] = src_[i] +  j * stride[i];
> +s->plane[i].line[j] = src_ +  j * stride[i];
>  }
>  
>  }
> diff --git a/libswscale/swscale_unscaled.c b/libswscale/swscale_unscaled.c
> index 563de39696..39fb7cc87f 100644
> --- a/libswscale/swscale_unscaled.c
> +++ b/libswscale/swscale_unscaled.c
> @@ -1806,6 +1806,9 @@ static int planarCopyWrapper(SwsContext *c, const 
> uint8_t *src[],
>  const AVPixFmtDescriptor *desc_dst = av_pix_fmt_desc_get(c->dstFormat);
>  int plane, i, j;
>  for (plane = 0; plane < 4; plane++) {
> +if (!dst[plane])
> +continue;
> +
>  int length = (plane == 0 || plane == 3) ? c->srcW  : 
> AV_CEIL_RSHIFT(c->srcW,   c->chrDstHSubSample);
>  int y =  (plane == 0 || plane == 3) ? srcSliceY: 
> AV_CEIL_RSHIFT(srcSliceY, c->chrDstVSubSample);
>  int height = (plane == 0 || plane == 3) ? srcSliceH: 
> AV_CEIL_RSHIFT(srcSliceH, c->chrDstVSubSample);

This produces new warnings:
libswscale/swscale_unscaled.c: In function ‘planarCopyWrapper’:
libswscale/swscale_unscaled.c:1812:9: warning: ISO C90 forbids mixed 
declarations and code [-Wdeclaration-after-statement]
 int length = (plane == 0 || plane == 3) ? c->srcW  : 
AV_CEIL_RSHIFT(c->srcW,   c->chrDstHSubSample);
 ^~~


thx

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

I am the wisest man alive, for I know one thing, and that is that I know
nothing. -- Socrates


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

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

Re: [FFmpeg-devel] [PATCH] libswscale/swscale.c: Clarify what exactly 'data is not aligned' to

2020-12-21 Thread Michael Niedermayer
On Sat, Dec 19, 2020 at 07:50:39PM +0100, Franziska Thul wrote:
> libswscale/swscale.c emits a Warning that 'data is not aligned', but doesn't 
> explain
> why, leaving users without any clue on how to address this issue.
> This patch simply adds that data is not aligned 'to 16 pixel boundaries'.
> 
> Idealy, the warning would say which values are not aligned, too, but since the
> variables' uses are probably explained elsewhere, I could only speculate.
> 
> ---
>  libswscale/swscale.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/libswscale/swscale.c b/libswscale/swscale.c
> index 9cb7e8f6ac..69349a7349 100644
> --- a/libswscale/swscale.c
> +++ b/libswscale/swscale.c
> @@ -311,8 +311,7 @@ static int swscale(SwsContext *c, const uint8_t *src[],
>  static int warnedAlready = 0; // FIXME maybe move this into the 
> context
>  if (flags & SWS_PRINT_INFO && !warnedAlready) {
>  av_log(c, AV_LOG_WARNING,
> -   "Warning: dstStride is not aligned!\n"
> -   " ->cannot do aligned memory accesses anymore\n");
> +   "Warning: dstStride is not aligned to a 16 pixel 
> boundary! Cannot do aligned memory accesses anymore.\n");
>  warnedAlready = 1;
>  }
>  }
> @@ -325,7 +324,7 @@ static int swscale(SwsContext *c, const uint8_t *src[],
>  static int warnedAlready=0;
>  int cpu_flags = av_get_cpu_flags();
>  if (HAVE_MMXEXT && (cpu_flags & AV_CPU_FLAG_SSE2) && !warnedAlready){
> -av_log(c, AV_LOG_WARNING, "Warning: data is not aligned! This 
> can lead to a speed loss\n");
> +av_log(c, AV_LOG_WARNING, "Warning: data is not aligned to a 16 
> pixel boundary! This can lead to a speed loss.\n");
>  warnedAlready=1;
>  }

all the alignment is by byte not by pixel

thx

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

Opposition brings concord. Out of discord comes the fairest harmony.
-- Heraclitus


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

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

[FFmpeg-devel] [PATCH 3/3] avformat/rtsp: add satip_raw flag to receive raw mpegts stream

2020-12-21 Thread Aman Karmani
From: Aman Karmani 

This can be used to receive the raw mpegts stream from a SAT>IP server, by 
letting avformat handle the RTSP/RTP/UDP negotiation and setup, but then simply 
passing the MP2T stream through instead of demuxing it further.

For example, this command would demux/remux the mpegts stream:

ffmpeg -i 
'satip://192.168.1.99:554/?src=1&freq=12188&pol=h&ro=0.35&msys=dvbs&mtype=qpsk&plts=off&sr=27500&fec=34&pids=0,17,18,167,136,47,71'
 -map 0 -c copy -f mpegts -y remux.ts

Whereas this command would simply save the original stream with the original 
PIDs and PAT/PMT/etc:

ffmpeg -rtsp_flags satip_raw -i 
'satip://192.168.1.99:554/?src=1&freq=12188&pol=h&ro=0.35&msys=dvbs&mtype=qpsk&plts=off&sr=27500&fec=34&pids=0,17,18,167,136,47,71'
 -map 0 -c copy -f mpegtsraw -y raw.ts

Signed-off-by: Aman Karmani 
---
 libavformat/rtsp.c | 6 +-
 libavformat/rtsp.h | 1 +
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/libavformat/rtsp.c b/libavformat/rtsp.c
index 4a863dbac3..d3864c0c67 100644
--- a/libavformat/rtsp.c
+++ b/libavformat/rtsp.c
@@ -89,6 +89,7 @@ const AVOption ff_rtsp_options[] = {
 RTSP_FLAG_OPTS("rtsp_flags", "set RTSP flags"),
 { "listen", "wait for incoming connections", 0, AV_OPT_TYPE_CONST, {.i64 = 
RTSP_FLAG_LISTEN}, 0, 0, DEC, "rtsp_flags" },
 { "prefer_tcp", "try RTP via TCP first, if available", 0, 
AV_OPT_TYPE_CONST, {.i64 = RTSP_FLAG_PREFER_TCP}, 0, 0, DEC|ENC, "rtsp_flags" },
+{ "satip_raw", "export raw MPEG-TS stream instead of demuxing", 0, 
AV_OPT_TYPE_CONST, {.i64 = RTSP_FLAG_SATIP_RAW}, 0, 0, DEC, "rtsp_flags" },
 RTSP_MEDIATYPE_OPTS("allowed_media_types", "set media types to accept from 
the server"),
 { "min_port", "set minimum local UDP port", OFFSET(rtp_port_min), 
AV_OPT_TYPE_INT, {.i64 = RTSP_RTP_PORT_MIN}, 0, 65535, DEC|ENC },
 { "max_port", "set maximum local UDP port", OFFSET(rtp_port_max), 
AV_OPT_TYPE_INT, {.i64 = RTSP_RTP_PORT_MAX}, 0, 65535, DEC|ENC },
@@ -256,6 +257,9 @@ static int init_satip_stream(AVFormatContext *s)
 {
 RTSPState *rt = s->priv_data;
 RTSPStream *rtsp_st;
+const RTPDynamicProtocolHandler *handler =
+(rt->rtsp_flags & RTSP_FLAG_SATIP_RAW) ? &ff_mpegtsraw_dynamic_handler 
:
+ &ff_mpegts_dynamic_handler;
 rtsp_st = av_mallocz(sizeof(RTSPStream));
 if (!rtsp_st)
 return AVERROR(ENOMEM);
@@ -265,7 +269,7 @@ static int init_satip_stream(AVFormatContext *s)
 av_strlcpy(rtsp_st->control_url,
rt->control_uri, sizeof(rtsp_st->control_url));
 rtsp_st->sdp_payload_type = 33; // MP2T
-init_rtp_handler(&ff_mpegts_dynamic_handler, rtsp_st, NULL);
+init_rtp_handler(handler, rtsp_st, NULL);
 finalize_rtp_handler_init(s, rtsp_st, NULL);
 return 0;
 }
diff --git a/libavformat/rtsp.h b/libavformat/rtsp.h
index c7c3b3cb52..8a9424a1c5 100644
--- a/libavformat/rtsp.h
+++ b/libavformat/rtsp.h
@@ -429,6 +429,7 @@ typedef struct RTSPState {
 #define RTSP_FLAG_RTCP_TO_SOURCE 0x8 /**< Send RTCP packets to the source
   address of received packets. */
 #define RTSP_FLAG_PREFER_TCP  0x10   /**< Try RTP via TCP first if possible. */
+#define RTSP_FLAG_SATIP_RAW   0x20   /**< Export SAT>IP stream as raw MPEG-TS 
*/
 
 typedef struct RTSPSource {
 char addr[128]; /**< Source-specific multicast include source IP address 
(from SDP content) */
-- 
2.29.2

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

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

[FFmpeg-devel] [PATCH 2/3] avformat/rtpdec_mpegts: add ff_mpegtsraw_dynamic_handler

2020-12-21 Thread Aman Karmani
From: Aman Karmani 

Passthrough handler which can be used to receive MP2T stream
over RTP, and repackage it into a AV_CODEC_ID_MPEG2TS data stream.

Signed-off-by: Aman Karmani 
---
 libavformat/rtpdec_formats.h |  1 +
 libavformat/rtpdec_mpegts.c  | 55 
 2 files changed, 56 insertions(+)

diff --git a/libavformat/rtpdec_formats.h b/libavformat/rtpdec_formats.h
index dad2b8ac1b..ce349292df 100644
--- a/libavformat/rtpdec_formats.h
+++ b/libavformat/rtpdec_formats.h
@@ -74,6 +74,7 @@ extern const RTPDynamicProtocolHandler 
ff_mpeg_audio_robust_dynamic_handler;
 extern const RTPDynamicProtocolHandler ff_mpeg_video_dynamic_handler;
 extern const RTPDynamicProtocolHandler ff_mpeg4_generic_dynamic_handler;
 extern const RTPDynamicProtocolHandler ff_mpegts_dynamic_handler;
+extern const RTPDynamicProtocolHandler ff_mpegtsraw_dynamic_handler;
 extern const RTPDynamicProtocolHandler ff_ms_rtp_asf_pfa_handler;
 extern const RTPDynamicProtocolHandler ff_ms_rtp_asf_pfv_handler;
 extern const RTPDynamicProtocolHandler ff_qcelp_dynamic_handler;
diff --git a/libavformat/rtpdec_mpegts.c b/libavformat/rtpdec_mpegts.c
index 405271f744..6d5a547030 100644
--- a/libavformat/rtpdec_mpegts.c
+++ b/libavformat/rtpdec_mpegts.c
@@ -20,6 +20,7 @@
  */
 
 #include "libavutil/attributes.h"
+#include "libavformat/internal.h"
 #include "mpegts.h"
 #include "rtpdec_formats.h"
 
@@ -28,6 +29,7 @@ struct PayloadContext {
 int read_buf_index;
 int read_buf_size;
 uint8_t buf[RTP_MAX_PACKET_LENGTH];
+AVStream *raw;
 };
 
 static void mpegts_close_context(PayloadContext *data)
@@ -89,6 +91,50 @@ static int mpegts_handle_packet(AVFormatContext *ctx, 
PayloadContext *data,
 return 0;
 }
 
+static av_cold int mpegtsraw_init(AVFormatContext *ctx, int st_index,
+  PayloadContext *data)
+{
+AVStream *st;
+st = avformat_new_stream(ctx, NULL);
+if (!st)
+return AVERROR(ENOMEM);
+st->codecpar->codec_type = AVMEDIA_TYPE_DATA;
+st->codecpar->codec_id   = AV_CODEC_ID_MPEG2TS;
+data->raw = st;
+return 0;
+}
+
+static int mpegtsraw_handle_packet(AVFormatContext *ctx, PayloadContext *data,
+   AVStream *st, AVPacket *pkt, uint32_t 
*timestamp,
+   const uint8_t *buf, int len, uint16_t seq,
+   int flags)
+{
+int ret;
+
+// We don't want to use the RTP timestamps at all. If the mpegts demuxer
+// doesn't set any pts/dts, the generic rtpdec code shouldn't try to
+// fill it in either, since the mpegts and RTP timestamps are in totally
+// different ranges.
+*timestamp = RTP_NOTS_VALUE;
+
+if (!buf || len < 188) {
+return AVERROR_INVALIDDATA;
+}
+
+if ((ret = av_new_packet(pkt, len)) < 0)
+return ret;
+memcpy(pkt->data, buf, len);
+pkt->stream_index = data->raw->index;
+return 0;
+}
+
+static void mpegtsraw_close_context(PayloadContext *data)
+{
+if (!data)
+return;
+data->raw = NULL;
+}
+
 const RTPDynamicProtocolHandler ff_mpegts_dynamic_handler = {
 .codec_type= AVMEDIA_TYPE_DATA,
 .priv_data_size= sizeof(PayloadContext),
@@ -97,3 +143,12 @@ const RTPDynamicProtocolHandler ff_mpegts_dynamic_handler = 
{
 .close = mpegts_close_context,
 .static_payload_id = 33,
 };
+
+const RTPDynamicProtocolHandler ff_mpegtsraw_dynamic_handler = {
+.codec_type= AVMEDIA_TYPE_DATA,
+.priv_data_size= sizeof(PayloadContext),
+.parse_packet  = mpegtsraw_handle_packet,
+.init  = mpegtsraw_init,
+.close = mpegtsraw_close_context,
+.static_payload_id = 33,
+};
-- 
2.29.2

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

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

Re: [FFmpeg-devel] [PATCH] avformat: add mpegtsraw muxer

2020-12-21 Thread Andreas Rheinhardt
Aman Karmani:
> From: Aman Karmani 
> 
> Allows easier writing of a AV_CODEC_ID_MPEG2TS stream out to disk.
> 
> Signed-off-by: Aman Karmani 
> ---
>  libavformat/Makefile |  1 +
>  libavformat/allformats.c |  1 +
>  libavformat/rawenc.c | 14 ++
>  3 files changed, 16 insertions(+)
> 
> diff --git a/libavformat/Makefile b/libavformat/Makefile
> index 97d868081b..ad528de589 100644
> --- a/libavformat/Makefile
> +++ b/libavformat/Makefile
> @@ -350,6 +350,7 @@ OBJS-$(CONFIG_MPEG2VOB_MUXER)+= mpegenc.o
>  OBJS-$(CONFIG_MPEGPS_DEMUXER)+= mpeg.o
>  OBJS-$(CONFIG_MPEGTS_DEMUXER)+= mpegts.o
>  OBJS-$(CONFIG_MPEGTS_MUXER)  += mpegtsenc.o
> +OBJS-$(CONFIG_MPEGTSRAW_MUXER)   += rawenc.o
>  OBJS-$(CONFIG_MPEGVIDEO_DEMUXER) += mpegvideodec.o rawdec.o
>  OBJS-$(CONFIG_MPJPEG_DEMUXER)+= mpjpegdec.o
>  OBJS-$(CONFIG_MPJPEG_MUXER)  += mpjpeg.o
> diff --git a/libavformat/allformats.c b/libavformat/allformats.c
> index 0e0caaad39..6106344ba0 100644
> --- a/libavformat/allformats.c
> +++ b/libavformat/allformats.c
> @@ -279,6 +279,7 @@ extern AVInputFormat  ff_mpegps_demuxer;
>  extern AVInputFormat  ff_mpegts_demuxer;
>  extern AVOutputFormat ff_mpegts_muxer;
>  extern AVInputFormat  ff_mpegtsraw_demuxer;
> +extern AVOutputFormat ff_mpegtsraw_muxer;
>  extern AVInputFormat  ff_mpegvideo_demuxer;
>  extern AVInputFormat  ff_mpjpeg_demuxer;
>  extern AVOutputFormat ff_mpjpeg_muxer;
> diff --git a/libavformat/rawenc.c b/libavformat/rawenc.c
> index 32704f9bfd..38def493cf 100644
> --- a/libavformat/rawenc.c
> +++ b/libavformat/rawenc.c
> @@ -465,6 +465,20 @@ AVOutputFormat ff_mpeg2video_muxer = {
>  };
>  #endif
>  
> +#if CONFIG_MPEGTSRAW_MUXER
> +AVOutputFormat ff_mpegtsraw_muxer = {
> +.name   = "mpegtsraw",
> +.long_name  = NULL_IF_CONFIG_SMALL("raw MPEG-TS"),
> +.mime_type  = "video/MP2T",
> +.extensions = "ts,m2t,m2ts,mts",
> +.audio_codec= AV_CODEC_ID_NONE,
> +.video_codec= AV_CODEC_ID_NONE,
> +.data_codec = AV_CODEC_ID_MPEG2TS,
> +.write_packet   = ff_raw_write_packet,
> +.flags  = AVFMT_NOTIMESTAMPS,
> +};
> +#endif
> +
>  #if CONFIG_RAWVIDEO_MUXER
>  AVOutputFormat ff_rawvideo_muxer = {
>  .name  = "rawvideo",
> 
Why don't you just use the data muxer instead of adding a new muxer with
the same extensions and mime type as an existing (and preferable) muxer?

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

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

[FFmpeg-devel] [PATCH 1/3] avformat/rtsp: add support for satip://

2020-12-21 Thread Aman Karmani
From: Aman Karmani 

The SAT>IP protocol[1] is similar to RTSP. However SAT>IP servers
are assumed to speak only MP2T, so DESCRIBE is not used in the same
way. When no streams are active, DESCRIBE will return 404 according
to the spec (see section 3.5.7). When streams are active, DESCRIBE
will return a list of all current streams along with information
about their signal strengths.

Previously, attemping to use ffmpeg with a rtsp:// url that points
to a SAT>IP server would work with some devices and fail due to 404
response on others. Further, if the SAT>IP server was already
streaming, ffmpeg would incorrectly consume the DESCRIBE SDP response
and join an existing tuner instead of requesting a new session with
the URL provided by the user. These issues have been noted by many
users across the internet[2][3].

This commit adds proper spec-compliant support for SAT>IP, including:

- support for the satip:// psuedo-protocol
- avoiding the use of DESCRIBE
- parsing and consuming the com.ses.streamID response header
- using "Transport: RTP/AVP;unicast" because the optional "/UDP"
  suffix confuses some servers

[1] 
https://www.satip.info/sites/satip/files/resource/satip_specification_version_1_2_2.pdf
[2] 
https://stackoverflow.com/questions/61194344/does-ffmpeg-violate-the-satip-specification-describe-syntax
[3] https://github.com/kodi-pvr/pvr.iptvsimple/issues/196
---
 libavformat/rtsp.c| 52 ++-
 libavformat/rtsp.h|  6 +
 libavformat/rtspdec.c |  1 +
 3 files changed, 53 insertions(+), 6 deletions(-)

diff --git a/libavformat/rtsp.c b/libavformat/rtsp.c
index c7ffa07d9e..4a863dbac3 100644
--- a/libavformat/rtsp.c
+++ b/libavformat/rtsp.c
@@ -252,6 +252,24 @@ static void finalize_rtp_handler_init(AVFormatContext *s, 
RTSPStream *rtsp_st,
 }
 }
 
+static int init_satip_stream(AVFormatContext *s)
+{
+RTSPState *rt = s->priv_data;
+RTSPStream *rtsp_st;
+rtsp_st = av_mallocz(sizeof(RTSPStream));
+if (!rtsp_st)
+return AVERROR(ENOMEM);
+rtsp_st->stream_index = -1;
+dynarray_add(&rt->rtsp_streams,
+ &rt->nb_rtsp_streams, rtsp_st);
+av_strlcpy(rtsp_st->control_url,
+   rt->control_uri, sizeof(rtsp_st->control_url));
+rtsp_st->sdp_payload_type = 33; // MP2T
+init_rtp_handler(&ff_mpegts_dynamic_handler, rtsp_st, NULL);
+finalize_rtp_handler_init(s, rtsp_st, NULL);
+return 0;
+}
+
 /* parse the rtpmap description: /[/] */
 static int sdp_parse_rtpmap(AVFormatContext *s,
 AVStream *st, RTSPStream *rtsp_st,
@@ -1116,6 +1134,9 @@ void ff_rtsp_parse_line(AVFormatContext *s,
 } else if (av_stristart(p, "Content-Type:", &p)) {
 p += strspn(p, SPACE_CHARS);
 av_strlcpy(reply->content_type, p, sizeof(reply->content_type));
+} else if (av_stristart(p, "com.ses.streamID:", &p)) {
+p += strspn(p, SPACE_CHARS);
+av_strlcpy(reply->stream_id, p, sizeof(reply->stream_id));
 }
 }
 
@@ -1495,8 +1516,10 @@ int ff_rtsp_make_setup_request(AVFormatContext *s, const 
char *host, int port,
 rtp_opened:
 port = ff_rtp_get_local_rtp_port(rtsp_st->rtp_handle);
 have_port:
-snprintf(transport, sizeof(transport) - 1,
- "%s/UDP;", trans_pref);
+av_strlcat(transport, trans_pref, sizeof(transport));
+av_strlcat(transport,
+   rt->server_type == RTSP_SERVER_SATIP ? ";" : "/UDP;",
+   sizeof(transport));
 if (rt->server_type != RTSP_SERVER_REAL)
 av_strlcat(transport, "unicast;", sizeof(transport));
 av_strlcatf(transport, sizeof(transport),
@@ -1559,6 +1582,15 @@ int ff_rtsp_make_setup_request(AVFormatContext *s, const 
char *host, int port,
 goto fail;
 }
 
+if (rt->server_type == RTSP_SERVER_SATIP && reply->stream_id[0]) {
+char proto[128], host[128], path[512], auth[128];
+int port;
+av_url_split(proto, sizeof(proto), auth, sizeof(auth), host, 
sizeof(host),
+&port, path, sizeof(path), rt->control_uri);
+ff_url_join(rt->control_uri, sizeof(rt->control_uri), proto, NULL, 
host,
+port, "/stream=%s", reply->stream_id);
+}
+
 /* XXX: same protocol for all streams is required */
 if (i > 0) {
 if (reply->transports[0].lower_transport != rt->lower_transport ||
@@ -1710,6 +1742,9 @@ redirect:
 lower_rtsp_proto = "tls";
 default_port = RTSPS_DEFAULT_PORT;
 rt->lower_transport_mask = 1 << RTSP_LOWER_TRANSPORT_TCP;
+} else if (!strcmp(proto, "satip")) {
+av_strlcpy(proto, "rtsp", sizeof(proto));
+rt->server_type = RTSP_SERVER_SATIP;
 }
 
 if (*auth) {
@@ -1857,7 +1892,9 @@ redirect:
 
 /* request options supported by the server; this also detects server
  

Re: [FFmpeg-devel] [PATCH] avformat: add mpegtsraw muxer

2020-12-21 Thread Aman Gupta
On Mon, Dec 21, 2020 at 4:58 PM Andreas Rheinhardt <
andreas.rheinha...@gmail.com> wrote:

> Aman Karmani:
> > From: Aman Karmani 
> >
> > Allows easier writing of a AV_CODEC_ID_MPEG2TS stream out to disk.
> >
> > Signed-off-by: Aman Karmani 
> > ---
> >  libavformat/Makefile |  1 +
> >  libavformat/allformats.c |  1 +
> >  libavformat/rawenc.c | 14 ++
> >  3 files changed, 16 insertions(+)
> >
> > diff --git a/libavformat/Makefile b/libavformat/Makefile
> > index 97d868081b..ad528de589 100644
> > --- a/libavformat/Makefile
> > +++ b/libavformat/Makefile
> > @@ -350,6 +350,7 @@ OBJS-$(CONFIG_MPEG2VOB_MUXER)+= mpegenc.o
> >  OBJS-$(CONFIG_MPEGPS_DEMUXER)+= mpeg.o
> >  OBJS-$(CONFIG_MPEGTS_DEMUXER)+= mpegts.o
> >  OBJS-$(CONFIG_MPEGTS_MUXER)  += mpegtsenc.o
> > +OBJS-$(CONFIG_MPEGTSRAW_MUXER)   += rawenc.o
> >  OBJS-$(CONFIG_MPEGVIDEO_DEMUXER) += mpegvideodec.o rawdec.o
> >  OBJS-$(CONFIG_MPJPEG_DEMUXER)+= mpjpegdec.o
> >  OBJS-$(CONFIG_MPJPEG_MUXER)  += mpjpeg.o
> > diff --git a/libavformat/allformats.c b/libavformat/allformats.c
> > index 0e0caaad39..6106344ba0 100644
> > --- a/libavformat/allformats.c
> > +++ b/libavformat/allformats.c
> > @@ -279,6 +279,7 @@ extern AVInputFormat  ff_mpegps_demuxer;
> >  extern AVInputFormat  ff_mpegts_demuxer;
> >  extern AVOutputFormat ff_mpegts_muxer;
> >  extern AVInputFormat  ff_mpegtsraw_demuxer;
> > +extern AVOutputFormat ff_mpegtsraw_muxer;
> >  extern AVInputFormat  ff_mpegvideo_demuxer;
> >  extern AVInputFormat  ff_mpjpeg_demuxer;
> >  extern AVOutputFormat ff_mpjpeg_muxer;
> > diff --git a/libavformat/rawenc.c b/libavformat/rawenc.c
> > index 32704f9bfd..38def493cf 100644
> > --- a/libavformat/rawenc.c
> > +++ b/libavformat/rawenc.c
> > @@ -465,6 +465,20 @@ AVOutputFormat ff_mpeg2video_muxer = {
> >  };
> >  #endif
> >
> > +#if CONFIG_MPEGTSRAW_MUXER
> > +AVOutputFormat ff_mpegtsraw_muxer = {
> > +.name   = "mpegtsraw",
> > +.long_name  = NULL_IF_CONFIG_SMALL("raw MPEG-TS"),
> > +.mime_type  = "video/MP2T",
> > +.extensions = "ts,m2t,m2ts,mts",
> > +.audio_codec= AV_CODEC_ID_NONE,
> > +.video_codec= AV_CODEC_ID_NONE,
> > +.data_codec = AV_CODEC_ID_MPEG2TS,
> > +.write_packet   = ff_raw_write_packet,
> > +.flags  = AVFMT_NOTIMESTAMPS,
> > +};
> > +#endif
> > +
> >  #if CONFIG_RAWVIDEO_MUXER
> >  AVOutputFormat ff_rawvideo_muxer = {
> >  .name  = "rawvideo",
> >
> Why don't you just use the data muxer instead of adding a new muxer with
> the same extensions and mime type as an existing (and preferable) muxer?
>

I missed the generic data muxer, thanks for pointing it out. Please
disregard this patch.

Aman


> - Andreas
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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

Re: [FFmpeg-devel] [PATCH] dnn: add NV12 pixel format support

2020-12-21 Thread Guo, Yejun


> -Original Message-
> From: ffmpeg-devel  On Behalf Of Ting Fu
> Sent: 2020年12月18日 16:08
> To: ffmpeg-devel@ffmpeg.org
> Subject: [FFmpeg-devel] [PATCH] dnn: add NV12 pixel format support
> 
> Signed-off-by: Ting Fu 
> ---
>  libavfilter/dnn/dnn_io_proc.c   |  2 ++
>  libavfilter/vf_dnn_processing.c | 30 +-
>  2 files changed, 23 insertions(+), 9 deletions(-)
> 
> diff --git a/libavfilter/dnn/dnn_io_proc.c b/libavfilter/dnn/dnn_io_proc.c 
> index
> c9b49be3bd..2744cb6502 100644
> --- a/libavfilter/dnn/dnn_io_proc.c
> +++ b/libavfilter/dnn/dnn_io_proc.c
> @@ -64,6 +64,7 @@ DNNReturnType proc_from_dnn_to_frame(AVFrame
> *frame, DNNData *output, void *log_
>  case AV_PIX_FMT_YUV410P:
>  case AV_PIX_FMT_YUV411P:
>  case AV_PIX_FMT_GRAY8:
> +case AV_PIX_FMT_NV12:
>  sws_ctx = sws_getContext(frame->width,
>   frame->height,
>   AV_PIX_FMT_GRAYF32, @@ -135,6
> +136,7 @@ DNNReturnType proc_from_frame_to_dnn(AVFrame *frame,
> DNNData *input, void *log_c
>  case AV_PIX_FMT_YUV410P:
>  case AV_PIX_FMT_YUV411P:
>  case AV_PIX_FMT_GRAY8:
> +case AV_PIX_FMT_NV12:
>  sws_ctx = sws_getContext(frame->width,
>   frame->height,
>   AV_PIX_FMT_GRAY8, diff --git
> a/libavfilter/vf_dnn_processing.c b/libavfilter/vf_dnn_processing.c index
> 334243bd2b..76fd2e88db 100644
> --- a/libavfilter/vf_dnn_processing.c
> +++ b/libavfilter/vf_dnn_processing.c
> @@ -113,6 +113,7 @@ static int query_formats(AVFilterContext *context)
>  AV_PIX_FMT_GRAY8, AV_PIX_FMT_GRAYF32,
>  AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUV422P,
>  AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUV410P,
> AV_PIX_FMT_YUV411P,
> +AV_PIX_FMT_NV12,
>  AV_PIX_FMT_NONE
>  };
>  AVFilterFormats *fmts_list = ff_make_format_list(pix_fmts); @@ -161,6
> +162,7 @@ static int check_modelinput_inlink(const DNNData *model_input,
> const AVFilterLin
>  case AV_PIX_FMT_YUV444P:
>  case AV_PIX_FMT_YUV410P:
>  case AV_PIX_FMT_YUV411P:
> +case AV_PIX_FMT_NV12:
>  if (model_input->channels != 1) {
>  LOG_FORMAT_CHANNEL_MISMATCH();
>  return AVERROR(EIO);
> @@ -212,15 +214,22 @@ static int prepare_uv_scale(AVFilterLink *outlink)
> 
>  if (isPlanarYUV(fmt)) {
>  if (inlink->w != outlink->w || inlink->h != outlink->h) {
> -const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(fmt);
> -int sws_src_h = AV_CEIL_RSHIFT(inlink->h,
> desc->log2_chroma_h);
> -int sws_src_w = AV_CEIL_RSHIFT(inlink->w,
> desc->log2_chroma_w);
> -int sws_dst_h = AV_CEIL_RSHIFT(outlink->h,
> desc->log2_chroma_h);
> -int sws_dst_w = AV_CEIL_RSHIFT(outlink->w,
> desc->log2_chroma_w);
> -ctx->sws_uv_scale = sws_getContext(sws_src_w, sws_src_h,
> AV_PIX_FMT_GRAY8,
> -   sws_dst_w, sws_dst_h,
> AV_PIX_FMT_GRAY8,
> -   SWS_BICUBIC, NULL,
> NULL, NULL);
> -ctx->sws_uv_height = sws_src_h;
> +if (fmt == AV_PIX_FMT_NV12) {
> +ctx->sws_uv_scale = sws_getContext(inlink->w >> 1,
> inlink->h >> 1, AV_PIX_FMT_YA8,
> +   outlink->w >> 1,
> outlink->h >> 1, AV_PIX_FMT_YA8,
> +   SWS_BICUBIC,
> NULL, NULL, NULL);
> +ctx->sws_uv_height = inlink->h >> 1;
> +} else {
> +const AVPixFmtDescriptor *desc =
> av_pix_fmt_desc_get(fmt);
> +int sws_src_h = AV_CEIL_RSHIFT(inlink->h,
> desc->log2_chroma_h);
> +int sws_src_w = AV_CEIL_RSHIFT(inlink->w,
> desc->log2_chroma_w);
> +int sws_dst_h = AV_CEIL_RSHIFT(outlink->h,
> desc->log2_chroma_h);
> +int sws_dst_w = AV_CEIL_RSHIFT(outlink->w,
> desc->log2_chroma_w);
> +ctx->sws_uv_scale = sws_getContext(sws_src_w, sws_src_h,
> AV_PIX_FMT_GRAY8,
> +   sws_dst_w,
> sws_dst_h, AV_PIX_FMT_GRAY8,
> +   SWS_BICUBIC,
> NULL, NULL, NULL);
> +ctx->sws_uv_height = sws_src_h;
> +}
>  }
>  }
> 
> @@ -262,6 +271,9 @@ static int copy_uv_planes(DnnProcessingContext *ctx,
> AVFrame *out, const AVFrame
>  in->data[i], in->linesize[i],
>  bytewidth, uv_height);
>  }
> +} else if (in->format == AV_PIX_FMT_NV12) {
> +sws_scale(ctx->sws_uv_scale, (const uint8_t **)(in->data + 1),
> in->linesize + 1,
> +  0, ctx->sws_uv_height, out->data + 1, out->linesize +
> + 1);
>  } else {
>  sws_scale(ctx->sws_uv_scale, (const uint8_t **)(in->data + 1),
> in->linesize + 1,
>  

Re: [FFmpeg-devel] [PATCH 1/2] ffmpeg: add option stats_period

2020-12-21 Thread Gyan Doshi



On 22-12-2020 04:28 am, Michael Niedermayer wrote:

On Mon, Dec 21, 2020 at 02:51:20PM +0530, Gyan Doshi wrote:

At present, progress stats are updated at a hardcoded interval of
half a second. For long processes, this can lead to bloated
logs and progress reports.

Users can now set a custom period using option -stats_period
Default is kept at 0.5 seconds.
---
  doc/ffmpeg.texi  |  7 ++-
  fftools/ffmpeg.c |  2 +-
  fftools/ffmpeg.h |  1 +
  fftools/ffmpeg_opt.c | 18 ++
  4 files changed, 26 insertions(+), 2 deletions(-)

probably ok


Will push both patches in 12 hours if no further comments.

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

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

[FFmpeg-devel] [PATCH 1/8] vf_dnn_processing.c: replace filter_frame with activate func

2020-12-21 Thread Guo, Yejun
with this change, dnn_processing can use DNN async interface later.

Signed-off-by: Xie, Lin 
Signed-off-by: Wu Zhiwen 
Signed-off-by: Guo, Yejun 
---
 libavfilter/vf_dnn_processing.c | 49 +++--
 1 file changed, 47 insertions(+), 2 deletions(-)

diff --git a/libavfilter/vf_dnn_processing.c b/libavfilter/vf_dnn_processing.c
index 76fd2e88db..5aad899dd0 100644
--- a/libavfilter/vf_dnn_processing.c
+++ b/libavfilter/vf_dnn_processing.c
@@ -28,7 +28,7 @@
 #include "libavutil/pixdesc.h"
 #include "libavutil/avassert.h"
 #include "libavutil/imgutils.h"
-#include "avfilter.h"
+#include "filters.h"
 #include "dnn_interface.h"
 #include "formats.h"
 #include "internal.h"
@@ -315,6 +315,51 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
 return ff_filter_frame(outlink, out);
 }
 
+static int activate_sync(AVFilterContext *filter_ctx)
+{
+AVFilterLink *inlink = filter_ctx->inputs[0];
+AVFilterLink *outlink = filter_ctx->outputs[0];
+AVFrame *in = NULL;
+int64_t pts;
+int ret, status;
+int got_frame = 0;
+
+FF_FILTER_FORWARD_STATUS_BACK(outlink, inlink);
+
+do {
+// drain all input frames
+ret = ff_inlink_consume_frame(inlink, &in);
+if (ret < 0)
+return ret;
+if (ret > 0) {
+ret = filter_frame(inlink, in);
+if (ret < 0)
+return ret;
+got_frame = 1;
+}
+} while (ret > 0);
+
+// if frame got, schedule to next filter
+if (got_frame)
+return 0;
+
+if (ff_inlink_acknowledge_status(inlink, &status, &pts)) {
+if (status == AVERROR_EOF) {
+ff_outlink_set_status(outlink, status, pts);
+return ret;
+}
+}
+
+FF_FILTER_FORWARD_WANTED(outlink, inlink);
+
+return FFERROR_NOT_READY;
+}
+
+static int activate(AVFilterContext *filter_ctx)
+{
+return activate_sync(filter_ctx);
+}
+
 static av_cold void uninit(AVFilterContext *ctx)
 {
 DnnProcessingContext *context = ctx->priv;
@@ -332,7 +377,6 @@ static const AVFilterPad dnn_processing_inputs[] = {
 .name = "default",
 .type = AVMEDIA_TYPE_VIDEO,
 .config_props = config_input,
-.filter_frame = filter_frame,
 },
 { NULL }
 };
@@ -356,4 +400,5 @@ AVFilter ff_vf_dnn_processing = {
 .inputs= dnn_processing_inputs,
 .outputs   = dnn_processing_outputs,
 .priv_class= &dnn_processing_class,
+.activate  = activate,
 };
-- 
2.17.1

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

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

[FFmpeg-devel] [PATCH 2/8] dnn/queue: add queue and safe_queue support

2020-12-21 Thread Guo, Yejun
From: "Xie, Lin" 

Signed-off-by: Xie, Lin 
Signed-off-by: Wu Zhiwen 
Signed-off-by: Guo, Yejun 
---
 libavfilter/dnn/Makefile |   2 +
 libavfilter/dnn/queue.c  | 176 +++
 libavfilter/dnn/queue.h  |  41 
 libavfilter/dnn/safe_queue.c |  92 ++
 libavfilter/dnn/safe_queue.h |  36 +++
 5 files changed, 347 insertions(+)
 create mode 100644 libavfilter/dnn/queue.c
 create mode 100644 libavfilter/dnn/queue.h
 create mode 100644 libavfilter/dnn/safe_queue.c
 create mode 100644 libavfilter/dnn/safe_queue.h

diff --git a/libavfilter/dnn/Makefile b/libavfilter/dnn/Makefile
index b0b76301ec..d6d58f4b61 100644
--- a/libavfilter/dnn/Makefile
+++ b/libavfilter/dnn/Makefile
@@ -1,5 +1,7 @@
 OBJS-$(CONFIG_DNN)   += dnn/dnn_interface.o
 OBJS-$(CONFIG_DNN)   += dnn/dnn_io_proc.o
+OBJS-$(CONFIG_DNN)   += dnn/queue.o
+OBJS-$(CONFIG_DNN)   += dnn/safe_queue.o
 OBJS-$(CONFIG_DNN)   += dnn/dnn_backend_native.o
 OBJS-$(CONFIG_DNN)   += dnn/dnn_backend_native_layers.o
 OBJS-$(CONFIG_DNN)   += 
dnn/dnn_backend_native_layer_avgpool.o
diff --git a/libavfilter/dnn/queue.c b/libavfilter/dnn/queue.c
new file mode 100644
index 00..0a07c5473d
--- /dev/null
+++ b/libavfilter/dnn/queue.c
@@ -0,0 +1,176 @@
+/*
+ * Copyright (c) 2020
+ *
+ * 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 
+#include "queue.h"
+#include "libavutil/mem.h"
+#include "libavutil/avassert.h"
+
+typedef struct _queue_entry queue_entry;
+
+typedef struct _queue {
+queue_entry *head;
+queue_entry *tail;
+size_t length;
+}queue;
+
+typedef struct _queue_entry {
+void *value;
+queue_entry *prev;
+queue_entry *next;
+} queue_entry;
+
+static inline queue_entry *create_entry(void *val)
+{
+queue_entry *entry = av_malloc(sizeof(*entry));
+av_assert0(entry != NULL);
+entry->value = val;
+return entry;
+}
+
+queue* queue_create(void)
+{
+queue *q = av_malloc(sizeof(*q));
+if (!q)
+return NULL;
+
+q->head = create_entry(q);
+q->tail = create_entry(q);
+q->head->next = q->tail;
+q->tail->prev = q->head;
+q->head->prev = NULL;
+q->tail->next = NULL;
+q->length = 0;
+
+return q;
+}
+
+void queue_destroy(queue *q)
+{
+queue_entry *entry;
+if (!q)
+return;
+
+entry = q->head;
+while (entry != NULL) {
+queue_entry *temp = entry;
+entry = entry->next;
+av_freep(&temp);
+}
+
+av_freep(&q);
+}
+
+size_t queue_size(queue *q)
+{
+ return q ? q->length : 0;
+}
+
+void *queue_peek_front(queue *q)
+{
+if (!q || q->length == 0)
+return NULL;
+
+return q->head->next->value;
+}
+
+void *queue_peek_back(queue *q)
+{
+if (!q || q->length == 0)
+return NULL;
+
+return q->tail->prev->value;
+}
+
+void queue_push_front(queue *q, void *v)
+{
+queue_entry *new_entry;
+queue_entry *original_next;
+if (!q)
+return;
+
+new_entry = create_entry(v);
+original_next = q->head->next;
+
+q->head->next = new_entry;
+original_next->prev = new_entry;
+new_entry->prev = q->head;
+new_entry->next = original_next;
+q->length++;
+}
+
+void queue_push_back(queue *q, void *v)
+{
+queue_entry *new_entry;
+queue_entry *original_prev;
+if (!q)
+return;
+
+new_entry = create_entry(v);
+original_prev = q->tail->prev;
+
+q->tail->prev = new_entry;
+original_prev->next = new_entry;
+new_entry->next = q->tail;
+new_entry->prev = original_prev;
+q->length++;
+}
+
+void *queue_pop_front(queue *q)
+{
+queue_entry *front;
+queue_entry *new_head_next;
+void *ret;
+
+if (!q || q->length == 0)
+return NULL;
+
+front = q->head->next;
+new_head_next = front->next;
+ret = front->value;
+
+q->head->next = new_head_next;
+new_head_next->prev = q->head;
+
+av_freep(&front);
+q->length--;
+return ret;
+}
+
+void *queue_pop_back(queue *q)
+{
+queue_entry *back;
+queue_entry *new_tail_prev;
+void *ret;
+
+if (!q || q->length == 0)
+ 

[FFmpeg-devel] [PATCH 3/8] dnn_backend_openvino.c: separate function execute_model_ov

2020-12-21 Thread Guo, Yejun
function fill_model_input_ov and infer_completion_callback are
extracted, it will help the async execution for reuse.

Signed-off-by: Xie, Lin 
Signed-off-by: Wu Zhiwen 
Signed-off-by: Guo, Yejun 
---
 libavfilter/dnn/dnn_backend_openvino.c | 292 +++--
 1 file changed, 175 insertions(+), 117 deletions(-)

diff --git a/libavfilter/dnn/dnn_backend_openvino.c 
b/libavfilter/dnn/dnn_backend_openvino.c
index d510e162c6..1196db0c90 100644
--- a/libavfilter/dnn/dnn_backend_openvino.c
+++ b/libavfilter/dnn/dnn_backend_openvino.c
@@ -50,6 +50,21 @@ typedef struct OVModel{
 ie_infer_request_t *infer_request;
 } OVModel;
 
+typedef struct TaskItem {
+OVModel *ov_model;
+const char *input_name;
+AVFrame *in_frame;
+const char *output_name;
+AVFrame *out_frame;
+int do_ioproc;
+int done;
+} TaskItem;
+
+typedef struct RequestItem {
+ie_infer_request_t *infer_request;
+TaskItem *task;
+} RequestItem;
+
 #define APPEND_STRING(generated_string, iterate_string)
\
 generated_string = generated_string ? av_asprintf("%s %s", 
generated_string, iterate_string) : \
   av_asprintf("%s", iterate_string);
@@ -63,10 +78,6 @@ static const AVOption dnn_openvino_options[] = {
 
 AVFILTER_DEFINE_CLASS(dnn_openvino);
 
-static DNNReturnType execute_model_ov(const DNNModel *model, const char 
*input_name, AVFrame *in_frame,
-  const char **output_names, uint32_t 
nb_output, AVFrame *out_frame,
-  int do_ioproc);
-
 static DNNDataType precision_to_datatype(precision_e precision)
 {
 switch (precision)
@@ -79,6 +90,136 @@ static DNNDataType precision_to_datatype(precision_e 
precision)
 }
 }
 
+static DNNReturnType fill_model_input_ov(OVModel *ov_model, TaskItem *task, 
RequestItem *request)
+{
+dimensions_t dims;
+precision_e precision;
+ie_blob_buffer_t blob_buffer;
+OVContext *ctx = &ov_model->ctx;
+IEStatusCode status;
+DNNData input;
+ie_blob_t *input_blob = NULL;
+
+status = ie_infer_request_get_blob(request->infer_request, 
task->input_name, &input_blob);
+if (status != OK) {
+av_log(ctx, AV_LOG_ERROR, "Failed to get input blob with name %s\n", 
task->input_name);
+return DNN_ERROR;
+}
+
+status |= ie_blob_get_dims(input_blob, &dims);
+status |= ie_blob_get_precision(input_blob, &precision);
+if (status != OK) {
+av_log(ctx, AV_LOG_ERROR, "Failed to get input blob dims/precision\n");
+return DNN_ERROR;
+}
+
+status = ie_blob_get_buffer(input_blob, &blob_buffer);
+if (status != OK) {
+av_log(ctx, AV_LOG_ERROR, "Failed to get input blob buffer\n");
+return DNN_ERROR;
+}
+
+input.height = dims.dims[2];
+input.width = dims.dims[3];
+input.channels = dims.dims[1];
+input.data = blob_buffer.buffer;
+input.dt = precision_to_datatype(precision);
+if (task->do_ioproc) {
+if (ov_model->model->pre_proc != NULL) {
+ov_model->model->pre_proc(task->in_frame, &input, 
ov_model->model->userdata);
+} else {
+proc_from_frame_to_dnn(task->in_frame, &input, ctx);
+}
+}
+ie_blob_free(&input_blob);
+
+return DNN_SUCCESS;
+}
+
+static void infer_completion_callback(void *args)
+{
+dimensions_t dims;
+precision_e precision;
+IEStatusCode status;
+RequestItem *request = args;
+TaskItem *task = request->task;
+ie_blob_t *output_blob = NULL;
+ie_blob_buffer_t blob_buffer;
+DNNData output;
+OVContext *ctx = &task->ov_model->ctx;
+
+status = ie_infer_request_get_blob(request->infer_request, 
task->output_name, &output_blob);
+if (status != OK) {
+//incorrect output name
+char *model_output_name = NULL;
+char *all_output_names = NULL;
+size_t model_output_count = 0;
+av_log(ctx, AV_LOG_ERROR, "Failed to get model output data\n");
+status = ie_network_get_outputs_number(task->ov_model->network, 
&model_output_count);
+for (size_t i = 0; i < model_output_count; i++) {
+status = ie_network_get_output_name(task->ov_model->network, i, 
&model_output_name);
+APPEND_STRING(all_output_names, model_output_name)
+}
+av_log(ctx, AV_LOG_ERROR,
+   "output \"%s\" may not correct, all output(s) are: \"%s\"\n",
+   task->output_name, all_output_names);
+return;
+}
+
+status = ie_blob_get_buffer(output_blob, &blob_buffer);
+if (status != OK) {
+av_log(ctx, AV_LOG_ERROR, "Failed to access output memory\n");
+return;
+}
+
+status |= ie_blob_get_dims(output_blob, &dims);
+status |= ie_blob_get_precision(output_blob, &precision);
+if (status != OK) {
+av_log(ctx, AV_LOG_ERROR, "Failed to get dims or precision of 
output\n");
+return;

[FFmpeg-devel] [PATCH 4/8] dnn_backend_openvino.c: refine code for error handle

2020-12-21 Thread Guo, Yejun
Signed-off-by: Xie, Lin 
Signed-off-by: Wu Zhiwen 
Signed-off-by: Guo, Yejun 
---
 libavfilter/dnn/dnn_backend_openvino.c | 22 ++
 1 file changed, 6 insertions(+), 16 deletions(-)

diff --git a/libavfilter/dnn/dnn_backend_openvino.c 
b/libavfilter/dnn/dnn_backend_openvino.c
index 1196db0c90..da6e640226 100644
--- a/libavfilter/dnn/dnn_backend_openvino.c
+++ b/libavfilter/dnn/dnn_backend_openvino.c
@@ -336,8 +336,11 @@ DNNModel *ff_dnn_load_model_ov(const char *model_filename, 
const char *options,
 }
 
 ov_model = av_mallocz(sizeof(OVModel));
-if (!ov_model)
-goto err;
+if (!ov_model) {
+av_freep(&model);
+return NULL;
+}
+model->model = (void *)ov_model;
 ov_model->model = model;
 ov_model->ctx.class = &dnn_openvino_class;
 ctx = &ov_model->ctx;
@@ -377,7 +380,6 @@ DNNModel *ff_dnn_load_model_ov(const char *model_filename, 
const char *options,
 if (status != OK)
 goto err;
 
-model->model = (void *)ov_model;
 model->get_input = &get_input_ov;
 model->get_output = &get_output_ov;
 model->options = options;
@@ -386,19 +388,7 @@ DNNModel *ff_dnn_load_model_ov(const char *model_filename, 
const char *options,
 return model;
 
 err:
-if (model)
-av_freep(&model);
-if (ov_model) {
-if (ov_model->infer_request)
-ie_infer_request_free(&ov_model->infer_request);
-if (ov_model->exe_network)
-ie_exec_network_free(&ov_model->exe_network);
-if (ov_model->network)
-ie_network_free(&ov_model->network);
-if (ov_model->core)
-ie_core_free(&ov_model->core);
-av_freep(&ov_model);
-}
+ff_dnn_free_model_ov(&model);
 return NULL;
 }
 
-- 
2.17.1

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

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

[FFmpeg-devel] [PATCH 5/8] dnn_interface: add interface to support async execution

2020-12-21 Thread Guo, Yejun
Signed-off-by: Xie, Lin 
Signed-off-by: Wu Zhiwen 
Signed-off-by: Guo, Yejun 
---
 libavfilter/dnn/dnn_interface.c |  2 +-
 libavfilter/dnn_interface.h | 12 
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/libavfilter/dnn/dnn_interface.c b/libavfilter/dnn/dnn_interface.c
index 7973d3e017..f82ab12e98 100644
--- a/libavfilter/dnn/dnn_interface.c
+++ b/libavfilter/dnn/dnn_interface.c
@@ -33,7 +33,7 @@ DNNModule *ff_get_dnn_module(DNNBackendType backend_type)
 {
 DNNModule *dnn_module;
 
-dnn_module = av_malloc(sizeof(DNNModule));
+dnn_module = av_mallocz(sizeof(DNNModule));
 if(!dnn_module){
 return NULL;
 }
diff --git a/libavfilter/dnn_interface.h b/libavfilter/dnn_interface.h
index 2f129d535e..9e54b91d19 100644
--- a/libavfilter/dnn_interface.h
+++ b/libavfilter/dnn_interface.h
@@ -35,6 +35,13 @@ typedef enum {DNN_NATIVE, DNN_TF, DNN_OV} DNNBackendType;
 
 typedef enum {DNN_FLOAT = 1, DNN_UINT8 = 4} DNNDataType;
 
+typedef enum {
+DAST_FAIL,  // something wrong
+DAST_EMPTY_QUEUE,   // no more inference result to get
+DAST_NOT_READY, // all queued inferences are not finished
+DAST_SUCCESS// got a result frame successfully
+} DNNAsyncStatusType;
+
 typedef struct DNNData{
 void *data;
 DNNDataType dt;
@@ -69,6 +76,11 @@ typedef struct DNNModule{
 // Executes model with specified input and output. Returns DNN_ERROR 
otherwise.
 DNNReturnType (*execute_model)(const DNNModel *model, const char 
*input_name, AVFrame *in_frame,
const char **output_names, uint32_t 
nb_output, AVFrame *out_frame);
+// Executes model with specified input and output asynchronously. Returns 
DNN_ERROR otherwise.
+DNNReturnType (*execute_model_async)(const DNNModel *model, const char 
*input_name, AVFrame *in_frame,
+ const char **output_names, uint32_t 
nb_output, AVFrame *out_frame);
+// Retrieve inference result.
+DNNAsyncStatusType (*get_async_result)(const DNNModel *model, AVFrame 
**out);
 // Frees memory allocated for model.
 void (*free_model)(DNNModel **model);
 } DNNModule;
-- 
2.17.1

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

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

[FFmpeg-devel] [PATCH 6/8] dnn: add async execution support for openvino backend

2020-12-21 Thread Guo, Yejun
Signed-off-by: Xie, Lin 
Signed-off-by: Wu Zhiwen 
Signed-off-by: Guo, Yejun 
---
 libavfilter/dnn/dnn_backend_openvino.c | 162 +++--
 libavfilter/dnn/dnn_backend_openvino.h |   3 +
 libavfilter/dnn/dnn_interface.c|   2 +
 libavfilter/dnn_interface.h|   2 +-
 4 files changed, 159 insertions(+), 10 deletions(-)

diff --git a/libavfilter/dnn/dnn_backend_openvino.c 
b/libavfilter/dnn/dnn_backend_openvino.c
index da6e640226..8c3ba8a6a8 100644
--- a/libavfilter/dnn/dnn_backend_openvino.c
+++ b/libavfilter/dnn/dnn_backend_openvino.c
@@ -30,10 +30,13 @@
 #include "libavutil/opt.h"
 #include "libavutil/avstring.h"
 #include "../internal.h"
+#include "queue.h"
+#include "safe_queue.h"
 #include 
 
 typedef struct OVOptions{
 char *device_type;
+int nireq;
 } OVOptions;
 
 typedef struct OVContext {
@@ -48,6 +51,10 @@ typedef struct OVModel{
 ie_network_t *network;
 ie_executable_network_t *exe_network;
 ie_infer_request_t *infer_request;
+
+/* for async execution */
+safe_queue *request_queue;  // holds RequestItem
+queue *task_queue;  // holds TaskItem
 } OVModel;
 
 typedef struct TaskItem {
@@ -57,12 +64,14 @@ typedef struct TaskItem {
 const char *output_name;
 AVFrame *out_frame;
 int do_ioproc;
+int async;
 int done;
 } TaskItem;
 
 typedef struct RequestItem {
 ie_infer_request_t *infer_request;
 TaskItem *task;
+ie_complete_call_back_t callback;
 } RequestItem;
 
 #define APPEND_STRING(generated_string, iterate_string)
\
@@ -73,6 +82,7 @@ typedef struct RequestItem {
 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM
 static const AVOption dnn_openvino_options[] = {
 { "device", "device to run model", OFFSET(options.device_type), 
AV_OPT_TYPE_STRING, { .str = "CPU" }, 0, 0, FLAGS },
+{ "nireq",  "number of request",   OFFSET(options.nireq),   
AV_OPT_TYPE_INT,{ .i64 = 0 }, 0, INT_MAX, FLAGS },
 { NULL }
 };
 
@@ -195,6 +205,12 @@ static void infer_completion_callback(void *args)
 task->out_frame->height = output.height;
 }
 ie_blob_free(&output_blob);
+
+if (task->async) {
+request->task = NULL;
+safe_queue_push_back(task->ov_model->request_queue, request);
+}
+
 task->done = 1;
 }
 
@@ -208,16 +224,29 @@ static DNNReturnType execute_model_ov(TaskItem *task, 
RequestItem *request)
 return ret;
 }
 
-status = ie_infer_request_infer(request->infer_request);
-if (status != OK) {
-av_log(ctx, AV_LOG_ERROR, "Failed to start synchronous model 
inference\n");
-return DNN_ERROR;
+if (task->async) {
+request->task = task;
+status = ie_infer_set_completion_callback(request->infer_request, 
&request->callback);
+if (status != OK) {
+av_log(ctx, AV_LOG_ERROR, "Failed to set completion callback for 
inference\n");
+return DNN_ERROR;
+}
+status = ie_infer_request_infer_async(request->infer_request);
+if (status != OK) {
+av_log(ctx, AV_LOG_ERROR, "Failed to start async inference\n");
+return DNN_ERROR;
+}
+return DNN_SUCCESS;
+} else {
+status = ie_infer_request_infer(request->infer_request);
+if (status != OK) {
+av_log(ctx, AV_LOG_ERROR, "Failed to start synchronous model 
inference\n");
+return DNN_ERROR;
+}
+request->task = task;
+infer_completion_callback(request);
+return task->done ? DNN_SUCCESS : DNN_ERROR;
 }
-
-request->task = task;
-infer_completion_callback(request);
-
-return task->done ? DNN_SUCCESS : DNN_ERROR;
 }
 
 static DNNReturnType get_input_ov(void *model, DNNData *input, const char 
*input_name)
@@ -303,6 +332,7 @@ static DNNReturnType get_output_ov(void *model, const char 
*input_name, int inpu
 
 task.done = 0;
 task.do_ioproc = 0;
+task.async = 0;
 task.input_name = input_name;
 task.in_frame = in_frame;
 task.output_name = output_name;
@@ -376,10 +406,44 @@ DNNModel *ff_dnn_load_model_ov(const char 
*model_filename, const char *options,
 goto err;
 }
 
+// create infer_request for sync execution
 status = ie_exec_network_create_infer_request(ov_model->exe_network, 
&ov_model->infer_request);
 if (status != OK)
 goto err;
 
+// create infer_requests for async execution
+if (ctx->options.nireq <= 0) {
+// the default value is a rough estimation
+ctx->options.nireq = av_cpu_count() / 2 + 1;
+}
+
+ov_model->request_queue = safe_queue_create();
+if (!ov_model->request_queue) {
+goto err;
+}
+
+for (int i = 0; i < ctx->options.nireq; i++) {
+ie_infer_request_t *request;
+RequestItem *item = av_mallocz(sizeof(*item));
+if (!item) {
+goto err;
+}
+status = ie_exec_network_create_infer_request(o

[FFmpeg-devel] [PATCH 7/8] dnn_interface: change from 'void *userdata' to 'AVFilterContext *filter_ctx'

2020-12-21 Thread Guo, Yejun
'void *' is too flexible, since we can derive info from
AVFilterContext*, so we just unify the interface with this data
structure.

Signed-off-by: Xie, Lin 
Signed-off-by: Wu Zhiwen 
Signed-off-by: Guo, Yejun 
---
 libavfilter/dnn/dnn_backend_native.c   |  8 
 libavfilter/dnn/dnn_backend_native.h   |  2 +-
 libavfilter/dnn/dnn_backend_openvino.c |  8 
 libavfilter/dnn/dnn_backend_openvino.h |  2 +-
 libavfilter/dnn/dnn_backend_tf.c   |  8 
 libavfilter/dnn/dnn_backend_tf.h   |  2 +-
 libavfilter/dnn_interface.h| 11 ++-
 libavfilter/vf_dnn_processing.c|  2 +-
 8 files changed, 22 insertions(+), 21 deletions(-)

diff --git a/libavfilter/dnn/dnn_backend_native.c 
b/libavfilter/dnn/dnn_backend_native.c
index 4fc3ba2044..5e7fc0f10c 100644
--- a/libavfilter/dnn/dnn_backend_native.c
+++ b/libavfilter/dnn/dnn_backend_native.c
@@ -112,7 +112,7 @@ static DNNReturnType get_output_native(void *model, const 
char *input_name, int
 // layers_num,layer_type,layer_parameterss,layer_type,layer_parameters...
 // For CONV layer: activation_function, input_num, output_num, kernel_size, 
kernel, biases
 // For DEPTH_TO_SPACE layer: block_size
-DNNModel *ff_dnn_load_model_native(const char *model_filename, const char 
*options, void *userdata)
+DNNModel *ff_dnn_load_model_native(const char *model_filename, const char 
*options, AVFilterContext *filter_ctx)
 {
 DNNModel *model = NULL;
 char header_expected[] = "FFMPEGDNNNATIVE";
@@ -255,7 +255,7 @@ DNNModel *ff_dnn_load_model_native(const char 
*model_filename, const char *optio
 
 model->get_input = &get_input_native;
 model->get_output = &get_output_native;
-model->userdata = userdata;
+model->filter_ctx = filter_ctx;
 
 return model;
 
@@ -318,7 +318,7 @@ static DNNReturnType execute_model_native(const DNNModel 
*model, const char *inp
 input.dt = oprd->data_type;
 if (do_ioproc) {
 if (native_model->model->pre_proc != NULL) {
-native_model->model->pre_proc(in_frame, &input, 
native_model->model->userdata);
+native_model->model->pre_proc(in_frame, &input, 
native_model->model->filter_ctx);
 } else {
 proc_from_frame_to_dnn(in_frame, &input, ctx);
 }
@@ -366,7 +366,7 @@ static DNNReturnType execute_model_native(const DNNModel 
*model, const char *inp
 
 if (do_ioproc) {
 if (native_model->model->post_proc != NULL) {
-native_model->model->post_proc(out_frame, &output, 
native_model->model->userdata);
+native_model->model->post_proc(out_frame, &output, 
native_model->model->filter_ctx);
 } else {
 proc_from_dnn_to_frame(out_frame, &output, ctx);
 }
diff --git a/libavfilter/dnn/dnn_backend_native.h 
b/libavfilter/dnn/dnn_backend_native.h
index 2d02c063d4..5acdbe0da7 100644
--- a/libavfilter/dnn/dnn_backend_native.h
+++ b/libavfilter/dnn/dnn_backend_native.h
@@ -128,7 +128,7 @@ typedef struct NativeModel{
 int32_t operands_num;
 } NativeModel;
 
-DNNModel *ff_dnn_load_model_native(const char *model_filename, const char 
*options, void *userdata);
+DNNModel *ff_dnn_load_model_native(const char *model_filename, const char 
*options, AVFilterContext *filter_ctx);
 
 DNNReturnType ff_dnn_execute_model_native(const DNNModel *model, const char 
*input_name, AVFrame *in_frame,
   const char **output_names, uint32_t 
nb_output, AVFrame *out_frame);
diff --git a/libavfilter/dnn/dnn_backend_openvino.c 
b/libavfilter/dnn/dnn_backend_openvino.c
index 8c3ba8a6a8..a35d72a38c 100644
--- a/libavfilter/dnn/dnn_backend_openvino.c
+++ b/libavfilter/dnn/dnn_backend_openvino.c
@@ -136,7 +136,7 @@ static DNNReturnType fill_model_input_ov(OVModel *ov_model, 
TaskItem *task, Requ
 input.dt = precision_to_datatype(precision);
 if (task->do_ioproc) {
 if (ov_model->model->pre_proc != NULL) {
-ov_model->model->pre_proc(task->in_frame, &input, 
ov_model->model->userdata);
+ov_model->model->pre_proc(task->in_frame, &input, 
ov_model->model->filter_ctx);
 } else {
 proc_from_frame_to_dnn(task->in_frame, &input, ctx);
 }
@@ -196,7 +196,7 @@ static void infer_completion_callback(void *args)
 output.data = blob_buffer.buffer;
 if (task->do_ioproc) {
 if (task->ov_model->model->post_proc != NULL) {
-task->ov_model->model->post_proc(task->out_frame, &output, 
task->ov_model->model->userdata);
+task->ov_model->model->post_proc(task->out_frame, &output, 
task->ov_model->model->filter_ctx);
 } else {
 proc_from_dnn_to_frame(task->out_frame, &output, ctx);
 }
@@ -350,7 +350,7 @@ static DNNReturnType get_output_ov(void *model, const char 
*input_name, int inpu
 return ret;
 }
 
-DNNModel *ff_dnn_load_model_ov(const char *model_filename, const char 
*options, void *userdata)
+DNNModel *ff_dnn_

[FFmpeg-devel] [PATCH 8/8] vf_dnn_processing.c: add async support

2020-12-21 Thread Guo, Yejun
Signed-off-by: Xie, Lin 
Signed-off-by: Wu Zhiwen 
Signed-off-by: Guo, Yejun 
---
 doc/filters.texi|  4 ++
 libavfilter/vf_dnn_processing.c | 78 -
 2 files changed, 81 insertions(+), 1 deletion(-)

diff --git a/doc/filters.texi b/doc/filters.texi
index d6a53624ee..3f10a29739 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -9959,6 +9959,10 @@ Set the input name of the dnn network.
 @item output
 Set the output name of the dnn network.
 
+@item async
+use DNN async execution if set (default: set),
+roll back to sync execution if the backend does not support async.
+
 @end table
 
 @subsection Examples
diff --git a/libavfilter/vf_dnn_processing.c b/libavfilter/vf_dnn_processing.c
index 342b06e6ae..da4508b50e 100644
--- a/libavfilter/vf_dnn_processing.c
+++ b/libavfilter/vf_dnn_processing.c
@@ -42,6 +42,7 @@ typedef struct DnnProcessingContext {
 char *model_inputname;
 char *model_outputname;
 char *backend_options;
+int async;
 
 DNNModule *dnn_module;
 DNNModel *model;
@@ -65,6 +66,7 @@ static const AVOption dnn_processing_options[] = {
 { "input",   "input name of the model",OFFSET(model_inputname),  
AV_OPT_TYPE_STRING,{ .str = NULL }, 0, 0, FLAGS },
 { "output",  "output name of the model",   OFFSET(model_outputname), 
AV_OPT_TYPE_STRING,{ .str = NULL }, 0, 0, FLAGS },
 { "options", "backend options",OFFSET(backend_options),  
AV_OPT_TYPE_STRING,{ .str = NULL }, 0, 0, FLAGS },
+{ "async",   "use DNN async inference",OFFSET(async),
AV_OPT_TYPE_BOOL,  { .i64 = 1}, 0, 1, FLAGS},
 { NULL }
 };
 
@@ -103,6 +105,11 @@ static av_cold int init(AVFilterContext *context)
 return AVERROR(EINVAL);
 }
 
+if (!ctx->dnn_module->execute_model_async && ctx->async) {
+ctx->async = 0;
+av_log(ctx, AV_LOG_WARNING, "this backend does not support async 
execution, roll back to sync.\n");
+}
+
 return 0;
 }
 
@@ -355,9 +362,78 @@ static int activate_sync(AVFilterContext *filter_ctx)
 return FFERROR_NOT_READY;
 }
 
+static int activate_async(AVFilterContext *filter_ctx)
+{
+AVFilterLink *inlink = filter_ctx->inputs[0];
+AVFilterLink *outlink = filter_ctx->outputs[0];
+DnnProcessingContext *ctx = (DnnProcessingContext *)filter_ctx->priv;
+AVFrame *in = NULL, *out = NULL;
+int64_t pts;
+int ret, status;
+int got_frame = 0;
+int async_state;
+
+FF_FILTER_FORWARD_STATUS_BACK(outlink, inlink);
+
+do {
+// drain all input frames
+ret = ff_inlink_consume_frame(inlink, &in);
+if (ret < 0)
+return ret;
+if (ret > 0) {
+out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
+if (!out) {
+av_frame_free(&in);
+return AVERROR(ENOMEM);
+}
+av_frame_copy_props(out, in);
+if ((ctx->dnn_module->execute_model_async)(ctx->model, 
ctx->model_inputname, in,
+   (const char 
**)&ctx->model_outputname, 1, out) != DNN_SUCCESS) {
+return FFERROR_NOT_READY;
+}
+}
+} while (ret > 0);
+
+// drain all processed frames
+do {
+AVFrame *in_frame = NULL;
+AVFrame *out_frame = NULL;
+async_state = (ctx->dnn_module->get_async_result)(ctx->model, 
&in_frame, &out_frame);
+if (out_frame) {
+if (isPlanarYUV(in_frame->format))
+copy_uv_planes(ctx, out_frame, in_frame);
+av_frame_free(&in_frame);
+ret = ff_filter_frame(outlink, out_frame);
+if (ret < 0)
+return ret;
+got_frame = 1;
+}
+} while (async_state == DAST_SUCCESS);
+
+// if frame got, schedule to next filter
+if (got_frame)
+return 0;
+
+if (ff_inlink_acknowledge_status(inlink, &status, &pts)) {
+if (status == AVERROR_EOF) {
+ff_outlink_set_status(outlink, status, pts);
+return ret;
+}
+}
+
+FF_FILTER_FORWARD_WANTED(outlink, inlink);
+
+return FFERROR_NOT_READY;
+}
+
 static int activate(AVFilterContext *filter_ctx)
 {
-return activate_sync(filter_ctx);
+DnnProcessingContext *ctx = filter_ctx->priv;
+
+if (ctx->async)
+return activate_async(filter_ctx);
+else
+return activate_sync(filter_ctx);
 }
 
 static av_cold void uninit(AVFilterContext *ctx)
-- 
2.17.1

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

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