Re: [FFmpeg-devel] [PATCH v3] avcodec/cbs_vp8: Add support for VP8 codec bitstream READ methods

2023-07-30 Thread Dai, Jianhui J



> -Original Message-
> From: ffmpeg-devel  On Behalf Of Dai,
> Jianhui J
> Sent: Tuesday, June 20, 2023 9:42 AM
> To: FFmpeg development discussions and patches 
> Subject: Re: [FFmpeg-devel] [PATCH v3] avcodec/cbs_vp8: Add support for VP8
> codec bitstream READ methods
> 
> 
> 
> > -Original Message-
> > From: Dai, Jianhui J
> > Sent: Thursday, June 8, 2023 11:18 AM
> > To: FFmpeg development discussions and patches
> > 
> > Subject: RE: [PATCH v3] avcodec/cbs_vp8: Add support for VP8 codec
> > bitstream READ methods
> >
> >
> >
> > > -Original Message-
> > > From: ffmpeg-devel  On Behalf Of
> > > Dai, Jianhui J
> > > Sent: Tuesday, May 30, 2023 4:00 PM
> > > To: ffmpeg-devel@ffmpeg.org
> > > Subject: [FFmpeg-devel] [PATCH v3] avcodec/cbs_vp8: Add support for
> > > VP8 codec bitstream READ methods
> > >
> > > This commit adds VP8 into cbs supported codec list, and enables the
> > > `trace_headers` bitstream filters to support VP8, besides existing
> > > AV1, H.264,
> > > H.265 and VP9. It can be useful to debug VP8 stream issues.
> > >
> > > Only the READ methods `read_unit` and `split_fragment` are
> > > implemented, the WRITE methods `write_unit` and `assemble_fragment`
> > > return `AVERROR_PATCHWELCOME` error code. It is because the CBS VP8
> > > WRITE is unlikely used by any applications at the moment. The WRITE
> > > methods can be added later if there are real requirments.
> > >
> > > TESTS: ffmpeg -i fate-suite/vp8/frame_size_change.webm -vcodec copy
> > > -bsf:v trace_headers -f null -
> > >
> > > Signed-off-by: Jianhui Dai 
> > > ---
> > >  configure|   4 +-
> > >  libavcodec/Makefile  |   1 +
> > >  libavcodec/cbs.c |   6 +
> > >  libavcodec/cbs_internal.h|   1 +
> > >  libavcodec/cbs_vp8.c | 360 +++
> > >  libavcodec/cbs_vp8.h | 112 +
> > >  libavcodec/cbs_vp8_syntax_template.c | 224 +
> > >  7 files changed, 707 insertions(+), 1 deletion(-)  create mode
> > > 100644 libavcodec/cbs_vp8.c  create mode 100644 libavcodec/cbs_vp8.h
> > > create mode
> > > 100644 libavcodec/cbs_vp8_syntax_template.c
> > >
> > > diff --git a/configure b/configure
> > > index bb7be67676..b8960d2639 100755
> > > --- a/configure
> > > +++ b/configure
> > > @@ -2432,6 +2432,7 @@ CONFIG_EXTRA="
> > >  cbs_h265
> > >  cbs_jpeg
> > >  cbs_mpeg2
> > > +cbs_vp8
> > >  cbs_vp9
> > >  deflate_wrapper
> > >  dirac_parse
> > > @@ -2713,6 +2714,7 @@ cbs_h264_select="cbs"
> > >  cbs_h265_select="cbs"
> > >  cbs_jpeg_select="cbs"
> > >  cbs_mpeg2_select="cbs"
> > > +cbs_vp8_select="cbs"
> > >  cbs_vp9_select="cbs"
> > >  dct_select="rdft"
> > >  deflate_wrapper_deps="zlib"
> > > @@ -3284,7 +3286,7 @@ h264_redundant_pps_bsf_select="cbs_h264"
> > >  hevc_metadata_bsf_select="cbs_h265"
> > >  mjpeg2jpeg_bsf_select="jpegtables"
> > >  mpeg2_metadata_bsf_select="cbs_mpeg2"
> > > -trace_headers_bsf_select="cbs"
> > > +trace_headers_bsf_select="cbs cbs_vp8"
> > >  vp9_metadata_bsf_select="cbs_vp9"
> > >
> > >  # external libraries
> > > diff --git a/libavcodec/Makefile b/libavcodec/Makefile index
> > > 3cfb7e..1c4f0da1d2 100644
> > > --- a/libavcodec/Makefile
> > > +++ b/libavcodec/Makefile
> > > @@ -78,6 +78,7 @@ OBJS-$(CONFIG_CBS_H264)+= cbs_h2645.o
> > > cbs_sei.o h2645_parse.o
> > >  OBJS-$(CONFIG_CBS_H265)+= cbs_h2645.o cbs_sei.o
> h2645_parse.o
> > >  OBJS-$(CONFIG_CBS_JPEG)+= cbs_jpeg.o
> > >  OBJS-$(CONFIG_CBS_MPEG2)   += cbs_mpeg2.o
> > > +OBJS-$(CONFIG_CBS_VP8) += cbs_vp8.o vpx_rac.o
> > >  OBJS-$(CONFIG_CBS_VP9) += cbs_vp9.o
> > >  OBJS-$(CONFIG_CRYSTALHD)   += crystalhd.o
> > >  OBJS-$(CONFIG_DCT) += dct.o dct32_fixed.o 
> > > dct32_float.o
> > > diff --git a/libavcodec/cbs.c b/libavcodec/cbs.c index
> > > 504197e06d..c77110abb1
> > > 100644
> > > --- a/libavcodec/cbs.c
> > > +++ b/libavcodec/cbs.c
> > > @@ -46,6 +46,9 @@ static const CodedBitstreamType *const
> > > cbs_type_table[] = {  #if CONFIG_CBS_MPEG2
> > >  _cbs_type_mpeg2,
> > >  #endif
> > > +#if CONFIG_CBS_VP8
> > > +_cbs_type_vp8,
> > > +#endif
> > >  #if CONFIG_CBS_VP9
> > >  _cbs_type_vp9,
> > >  #endif
> > > @@ -67,6 +70,9 @@ const enum AVCodecID ff_cbs_all_codec_ids[] = {
> > > #if
> > > CONFIG_CBS_MPEG2
> > >  AV_CODEC_ID_MPEG2VIDEO,
> > >  #endif
> > > +#if CONFIG_CBS_VP8
> > > +AV_CODEC_ID_VP8,
> > > +#endif
> > >  #if CONFIG_CBS_VP9
> > >  AV_CODEC_ID_VP9,
> > >  #endif
> > > diff --git a/libavcodec/cbs_internal.h b/libavcodec/cbs_internal.h
> > > index
> > > e585c77934..beaf8505d1 100644
> > > --- a/libavcodec/cbs_internal.h
> > > +++ b/libavcodec/cbs_internal.h
> > > @@ -247,6 +247,7 @@ extern const CodedBitstreamType
> > > ff_cbs_type_h264; extern const CodedBitstreamType ff_cbs_type_h265;
> > > 

Re: [FFmpeg-devel] [PATCH 1/2] fftools/opt_common: Use %c instead of %s to write single char

2023-07-30 Thread Andreas Rheinhardt
James Almer:
> On 7/30/2023 9:47 PM, Andreas Rheinhardt wrote:
>> Also combine multiple printfs.
>>
>> Signed-off-by: Andreas Rheinhardt 
>> ---
>>   fftools/opt_common.c | 28 ++--
>>   1 file changed, 14 insertions(+), 14 deletions(-)
>>
>> diff --git a/fftools/opt_common.c b/fftools/opt_common.c
>> index 7c996f140d..3881d5bbef 100644
>> --- a/fftools/opt_common.c
>> +++ b/fftools/opt_common.c
>> @@ -692,14 +692,13 @@ int show_codecs(void *optctx, const char *opt,
>> const char *arg)
>>   if (strstr(desc->name, "_deprecated"))
>>   continue;
>>   -    printf(" ");
>> -    printf(avcodec_find_decoder(desc->id) ? "D" : ".");
>> -    printf(avcodec_find_encoder(desc->id) ? "E" : ".");
>> -
>> -    printf("%c", get_media_type_char(desc->type));
>> -    printf((desc->props & AV_CODEC_PROP_INTRA_ONLY) ? "I" : ".");
>> -    printf((desc->props & AV_CODEC_PROP_LOSSY)  ? "L" : ".");
>> -    printf((desc->props & AV_CODEC_PROP_LOSSLESS)   ? "S" : ".");
>> +    printf(" %c%c%c%c%c%c",
>> +   avcodec_find_decoder(desc->id) ? 'D' : '.',
>> +   avcodec_find_encoder(desc->id) ? 'E' : '.',
>> +   get_media_type_char(desc->type),
>> +   (desc->props & AV_CODEC_PROP_INTRA_ONLY) ? 'I' : '.',
>> +   (desc->props & AV_CODEC_PROP_LOSSY)  ? 'L' : '.',
>> +   (desc->props & AV_CODEC_PROP_LOSSLESS)   ? 'S' : '.');
>>     printf(" %-20s %s", desc->name, desc->long_name ?
>> desc->long_name : "");
>>   @@ -747,12 +746,13 @@ static void print_codecs(int encoder)
>>   void *iter = NULL;
>>     while ((codec = next_codec_for_id(desc->id, ,
>> encoder))) {
>> -    printf(" %c", get_media_type_char(desc->type));
>> -    printf((codec->capabilities & AV_CODEC_CAP_FRAME_THREADS)
>> ? "F" : ".");
>> -    printf((codec->capabilities & AV_CODEC_CAP_SLICE_THREADS)
>> ? "S" : ".");
>> -    printf((codec->capabilities & AV_CODEC_CAP_EXPERIMENTAL) 
>> ? "X" : ".");
>> -    printf((codec->capabilities &
>> AV_CODEC_CAP_DRAW_HORIZ_BAND)?"B" : ".");
>> -    printf((codec->capabilities & AV_CODEC_CAP_DR1)  
>> ? "D" : ".");
>> +    printf(" %c%c%c%c%c%c",
>> +   get_media_type_char(desc->type),
>> +   (codec->capabilities &
>> AV_CODEC_CAP_FRAME_THREADS)   ? 'F' : '.',
>> +   (codec->capabilities &
>> AV_CODEC_CAP_SLICE_THREADS)   ? 'S' : '.',
>> +   (codec->capabilities &
>> AV_CODEC_CAP_EXPERIMENTAL)    ? 'X' : '.',
>> +   (codec->capabilities &
>> AV_CODEC_CAP_DRAW_HORIZ_BAND) ? 'B' : '.',
>> +   (codec->capabilities &
>> AV_CODEC_CAP_DR1) ? 'D' : '.');
>>     printf(" %-20s %s", codec->name, codec->long_name ?
>> codec->long_name : "");
>>   if (strcmp(codec->name, desc->name))
> 
> You could instead port this function to AVBPrint, to only print to
> stderr once.

I do not think this is a good idea as it would add another potential
source of errors (for the implicit (re)allocations that happen when
using the AVBPrint API).

- 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 1/2] fftools/opt_common: Use %c instead of %s to write single char

2023-07-30 Thread Andreas Rheinhardt
James Almer:
> On 7/30/2023 9:47 PM, Andreas Rheinhardt wrote:
>> Also combine multiple printfs.
>>
>> Signed-off-by: Andreas Rheinhardt 
>> ---
>>   fftools/opt_common.c | 28 ++--
>>   1 file changed, 14 insertions(+), 14 deletions(-)
>>
>> diff --git a/fftools/opt_common.c b/fftools/opt_common.c
>> index 7c996f140d..3881d5bbef 100644
>> --- a/fftools/opt_common.c
>> +++ b/fftools/opt_common.c
>> @@ -692,14 +692,13 @@ int show_codecs(void *optctx, const char *opt,
>> const char *arg)
>>   if (strstr(desc->name, "_deprecated"))
>>   continue;
>>   -    printf(" ");
>> -    printf(avcodec_find_decoder(desc->id) ? "D" : ".");
>> -    printf(avcodec_find_encoder(desc->id) ? "E" : ".");
>> -
>> -    printf("%c", get_media_type_char(desc->type));
>> -    printf((desc->props & AV_CODEC_PROP_INTRA_ONLY) ? "I" : ".");
>> -    printf((desc->props & AV_CODEC_PROP_LOSSY)  ? "L" : ".");
>> -    printf((desc->props & AV_CODEC_PROP_LOSSLESS)   ? "S" : ".");
>> +    printf(" %c%c%c%c%c%c",
>> +   avcodec_find_decoder(desc->id) ? 'D' : '.',
>> +   avcodec_find_encoder(desc->id) ? 'E' : '.',
>> +   get_media_type_char(desc->type),
>> +   (desc->props & AV_CODEC_PROP_INTRA_ONLY) ? 'I' : '.',
>> +   (desc->props & AV_CODEC_PROP_LOSSY)  ? 'L' : '.',
>> +   (desc->props & AV_CODEC_PROP_LOSSLESS)   ? 'S' : '.');
>>     printf(" %-20s %s", desc->name, desc->long_name ?
>> desc->long_name : "");
>>   @@ -747,12 +746,13 @@ static void print_codecs(int encoder)
>>   void *iter = NULL;
>>     while ((codec = next_codec_for_id(desc->id, ,
>> encoder))) {
>> -    printf(" %c", get_media_type_char(desc->type));
>> -    printf((codec->capabilities & AV_CODEC_CAP_FRAME_THREADS)
>> ? "F" : ".");
>> -    printf((codec->capabilities & AV_CODEC_CAP_SLICE_THREADS)
>> ? "S" : ".");
>> -    printf((codec->capabilities & AV_CODEC_CAP_EXPERIMENTAL) 
>> ? "X" : ".");
>> -    printf((codec->capabilities &
>> AV_CODEC_CAP_DRAW_HORIZ_BAND)?"B" : ".");
>> -    printf((codec->capabilities & AV_CODEC_CAP_DR1)  
>> ? "D" : ".");
>> +    printf(" %c%c%c%c%c%c",
>> +   get_media_type_char(desc->type),
>> +   (codec->capabilities &
>> AV_CODEC_CAP_FRAME_THREADS)   ? 'F' : '.',
>> +   (codec->capabilities &
>> AV_CODEC_CAP_SLICE_THREADS)   ? 'S' : '.',
>> +   (codec->capabilities &
>> AV_CODEC_CAP_EXPERIMENTAL)    ? 'X' : '.',
>> +   (codec->capabilities &
>> AV_CODEC_CAP_DRAW_HORIZ_BAND) ? 'B' : '.',
>> +   (codec->capabilities &
>> AV_CODEC_CAP_DR1) ? 'D' : '.');
>>     printf(" %-20s %s", codec->name, codec->long_name ?
>> codec->long_name : "");
>>   if (strcmp(codec->name, desc->name))
> 
> You could instead port this function to AVBPrint, to only print to
> stderr once.

I could do so, but it is not "instead" of this patch. It is mostly
orthogonal.
(Btw: printf output goes to stdout.)

- 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 1/2] fftools/opt_common: Use %c instead of %s to write single char

2023-07-30 Thread James Almer

On 7/30/2023 9:47 PM, Andreas Rheinhardt wrote:

Also combine multiple printfs.

Signed-off-by: Andreas Rheinhardt 
---
  fftools/opt_common.c | 28 ++--
  1 file changed, 14 insertions(+), 14 deletions(-)

diff --git a/fftools/opt_common.c b/fftools/opt_common.c
index 7c996f140d..3881d5bbef 100644
--- a/fftools/opt_common.c
+++ b/fftools/opt_common.c
@@ -692,14 +692,13 @@ int show_codecs(void *optctx, const char *opt, const char 
*arg)
  if (strstr(desc->name, "_deprecated"))
  continue;
  
-printf(" ");

-printf(avcodec_find_decoder(desc->id) ? "D" : ".");
-printf(avcodec_find_encoder(desc->id) ? "E" : ".");
-
-printf("%c", get_media_type_char(desc->type));
-printf((desc->props & AV_CODEC_PROP_INTRA_ONLY) ? "I" : ".");
-printf((desc->props & AV_CODEC_PROP_LOSSY)  ? "L" : ".");
-printf((desc->props & AV_CODEC_PROP_LOSSLESS)   ? "S" : ".");
+printf(" %c%c%c%c%c%c",
+   avcodec_find_decoder(desc->id) ? 'D' : '.',
+   avcodec_find_encoder(desc->id) ? 'E' : '.',
+   get_media_type_char(desc->type),
+   (desc->props & AV_CODEC_PROP_INTRA_ONLY) ? 'I' : '.',
+   (desc->props & AV_CODEC_PROP_LOSSY)  ? 'L' : '.',
+   (desc->props & AV_CODEC_PROP_LOSSLESS)   ? 'S' : '.');
  
  printf(" %-20s %s", desc->name, desc->long_name ? desc->long_name : "");
  
@@ -747,12 +746,13 @@ static void print_codecs(int encoder)

  void *iter = NULL;
  
  while ((codec = next_codec_for_id(desc->id, , encoder))) {

-printf(" %c", get_media_type_char(desc->type));
-printf((codec->capabilities & AV_CODEC_CAP_FRAME_THREADS) ? "F" : 
".");
-printf((codec->capabilities & AV_CODEC_CAP_SLICE_THREADS) ? "S" : 
".");
-printf((codec->capabilities & AV_CODEC_CAP_EXPERIMENTAL)  ? "X" : 
".");
-printf((codec->capabilities & AV_CODEC_CAP_DRAW_HORIZ_BAND)?"B" : 
".");
-printf((codec->capabilities & AV_CODEC_CAP_DR1)   ? "D" : 
".");
+printf(" %c%c%c%c%c%c",
+   get_media_type_char(desc->type),
+   (codec->capabilities & AV_CODEC_CAP_FRAME_THREADS)   ? 'F' 
: '.',
+   (codec->capabilities & AV_CODEC_CAP_SLICE_THREADS)   ? 'S' 
: '.',
+   (codec->capabilities & AV_CODEC_CAP_EXPERIMENTAL)? 'X' 
: '.',
+   (codec->capabilities & AV_CODEC_CAP_DRAW_HORIZ_BAND) ? 'B' 
: '.',
+   (codec->capabilities & AV_CODEC_CAP_DR1) ? 'D' 
: '.');
  
  printf(" %-20s %s", codec->name, codec->long_name ? codec->long_name : "");

  if (strcmp(codec->name, desc->name))


You could instead port this function to AVBPrint, to only print to 
stderr once.

___
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/2] fftools/opt_common: Don't add unnecessary " "

2023-07-30 Thread Andreas Rheinhardt
Before:
D.AIL. smackaudio   Smacker audio (decoders: smackaud )
After:
D.AIL. smackaudio   Smacker audio (decoders: smackaud)

Signed-off-by: Andreas Rheinhardt 
---
 fftools/opt_common.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/fftools/opt_common.c b/fftools/opt_common.c
index 3881d5bbef..02d7048c42 100644
--- a/fftools/opt_common.c
+++ b/fftools/opt_common.c
@@ -615,10 +615,10 @@ static void print_codecs_for_id(enum AVCodecID id, int 
encoder)
 void *iter = NULL;
 const AVCodec *codec;
 
-printf(" (%s: ", encoder ? "encoders" : "decoders");
+printf(" (%s:", encoder ? "encoders" : "decoders");
 
 while ((codec = next_codec_for_id(id, , encoder)))
-printf("%s ", codec->name);
+printf(" %s", codec->name);
 
 printf(")");
 }
-- 
2.34.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 1/2] fftools/opt_common: Use %c instead of %s to write single char

2023-07-30 Thread Andreas Rheinhardt
Also combine multiple printfs.

Signed-off-by: Andreas Rheinhardt 
---
 fftools/opt_common.c | 28 ++--
 1 file changed, 14 insertions(+), 14 deletions(-)

diff --git a/fftools/opt_common.c b/fftools/opt_common.c
index 7c996f140d..3881d5bbef 100644
--- a/fftools/opt_common.c
+++ b/fftools/opt_common.c
@@ -692,14 +692,13 @@ int show_codecs(void *optctx, const char *opt, const char 
*arg)
 if (strstr(desc->name, "_deprecated"))
 continue;
 
-printf(" ");
-printf(avcodec_find_decoder(desc->id) ? "D" : ".");
-printf(avcodec_find_encoder(desc->id) ? "E" : ".");
-
-printf("%c", get_media_type_char(desc->type));
-printf((desc->props & AV_CODEC_PROP_INTRA_ONLY) ? "I" : ".");
-printf((desc->props & AV_CODEC_PROP_LOSSY)  ? "L" : ".");
-printf((desc->props & AV_CODEC_PROP_LOSSLESS)   ? "S" : ".");
+printf(" %c%c%c%c%c%c",
+   avcodec_find_decoder(desc->id) ? 'D' : '.',
+   avcodec_find_encoder(desc->id) ? 'E' : '.',
+   get_media_type_char(desc->type),
+   (desc->props & AV_CODEC_PROP_INTRA_ONLY) ? 'I' : '.',
+   (desc->props & AV_CODEC_PROP_LOSSY)  ? 'L' : '.',
+   (desc->props & AV_CODEC_PROP_LOSSLESS)   ? 'S' : '.');
 
 printf(" %-20s %s", desc->name, desc->long_name ? desc->long_name : 
"");
 
@@ -747,12 +746,13 @@ static void print_codecs(int encoder)
 void *iter = NULL;
 
 while ((codec = next_codec_for_id(desc->id, , encoder))) {
-printf(" %c", get_media_type_char(desc->type));
-printf((codec->capabilities & AV_CODEC_CAP_FRAME_THREADS) ? "F" : 
".");
-printf((codec->capabilities & AV_CODEC_CAP_SLICE_THREADS) ? "S" : 
".");
-printf((codec->capabilities & AV_CODEC_CAP_EXPERIMENTAL)  ? "X" : 
".");
-printf((codec->capabilities & AV_CODEC_CAP_DRAW_HORIZ_BAND)?"B" : 
".");
-printf((codec->capabilities & AV_CODEC_CAP_DR1)   ? "D" : 
".");
+printf(" %c%c%c%c%c%c",
+   get_media_type_char(desc->type),
+   (codec->capabilities & AV_CODEC_CAP_FRAME_THREADS)   ? 'F' 
: '.',
+   (codec->capabilities & AV_CODEC_CAP_SLICE_THREADS)   ? 'S' 
: '.',
+   (codec->capabilities & AV_CODEC_CAP_EXPERIMENTAL)? 'X' 
: '.',
+   (codec->capabilities & AV_CODEC_CAP_DRAW_HORIZ_BAND) ? 'B' 
: '.',
+   (codec->capabilities & AV_CODEC_CAP_DR1) ? 'D' 
: '.');
 
 printf(" %-20s %s", codec->name, codec->long_name ? 
codec->long_name : "");
 if (strcmp(codec->name, desc->name))
-- 
2.34.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".


Re: [FFmpeg-devel] [PATCH 01/12] avradio/avformat/sdrdemux: Move agc_gain into local variable

2023-07-30 Thread Paul B Mahol
NAK to whole set.
___
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 08/12] avradio/avformat/sdrdemux: set wanted gain also when manually set

2023-07-30 Thread Michael Niedermayer
Signed-off-by: Michael Niedermayer 
---
 libavformat/sdrdemux.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/libavformat/sdrdemux.c b/libavformat/sdrdemux.c
index 8f0f4657f3..3f3390049c 100644
--- a/libavformat/sdrdemux.c
+++ b/libavformat/sdrdemux.c
@@ -1476,7 +1476,7 @@ static void *soapy_needs_bigger_buffers_worker(SDRContext 
*sdr)
 unsigned block_counter = 0;
 int64_t local_wanted_freq = 0;
 int64_t last_wanted_freq = 0;
-float wanted_gain = (sdr->min_gain + sdr->max_gain) / 2;
+float wanted_gain = sdr->sdr_gain < 0 ? (sdr->min_gain + sdr->max_gain) / 
2 : sdr->sdr_gain;
 float agc_gain = 0;
 
 sdr->remaining_file_block_size = 0;
@@ -1530,7 +1530,8 @@ static void *soapy_needs_bigger_buffers_worker(SDRContext 
*sdr)
 //And theres not much else we can do, an error message was already 
printed by ff_sdr_set_freq() in that case
 block_counter = 0; // we just changed the frequency, do not trust 
the next blocks content
 }
-if (sdr->sdr_gain == GAIN_SW_AGC &&
+if (sdr->sdr_gain != GAIN_SDR_AGC &&
+sdr->sdr_gain != GAIN_DEFAULT &&
 fabs(wanted_gain - agc_gain) > 0.001 &&
 sdr->set_gain_callback
 ) {
@@ -1539,6 +1540,7 @@ static void *soapy_needs_bigger_buffers_worker(SDRContext 
*sdr)
 agc_gain = wanted_gain;
 if (block_counter)
 block_counter = 1;
+av_log(avfmt, AV_LOG_DEBUG, "GAIN changed %f\n", wanted_gain);
 }
 }
 pthread_mutex_unlock(>mutex);
-- 
2.31.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 12/12] avradio/avformat/sdrdemux: replace heuristic FM scaling by logic

2023-07-30 Thread Michael Niedermayer
Signed-off-by: Michael Niedermayer 
---
 libavformat/sdrdemux.c |  4 +++-
 tests/ref/fate/sdr-fm  | 12 ++--
 2 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/libavformat/sdrdemux.c b/libavformat/sdrdemux.c
index bda7387213..f8590a2e18 100644
--- a/libavformat/sdrdemux.c
+++ b/libavformat/sdrdemux.c
@@ -1135,7 +1135,9 @@ static int demodulate_fm(SDRContext *sdr, Station 
*station, AVStream *st, AVPack
 if (!newbuf)
 return AVERROR(ENOMEM);
 
-scale  = 5 / (M_PI * 2*sdr->fm_block_size);
+//ATAN gives us +-PI the following 2 transforms scale by the given values, 
we reverse this here
+scale = 1.0 / (M_PI * sqrt(2*sdr->fm_block_size * 
2*sdr->fm_block_size_p2));
+
 for(i = 0; ifm_block_size_p2; i++) {
 float m, q;
 
diff --git a/tests/ref/fate/sdr-fm b/tests/ref/fate/sdr-fm
index ef76e4f584..526f53a2bd 100644
--- a/tests/ref/fate/sdr-fm
+++ b/tests/ref/fate/sdr-fm
@@ -15,11 +15,11 @@
 #channel_layout_name 2: stereo
 0,  0,  0,1,   32, 0xf553af75
 0,  1,  1,1,   32, 0xeabc15b3
-1,   8196,   8196, 4096, 8192, 0xdd0d10be
-2,   8196,   8196, 4096, 8192, 0x98c4f547
-1,  12292,  12292, 4096, 8192, 0xaf58fbdc
-2,  12292,  12292, 4096, 8192, 0x6d53f60a
+1,   8196,   8196, 4096, 8192, 0x12b50769
+2,   8196,   8196, 4096, 8192, 0xeb93fbff
+1,  12292,  12292, 4096, 8192, 0xba21feb7
+2,  12292,  12292, 4096, 8192, 0x3ef2fc7b
 0,  3,  3,1,   32, 0xf8b7b144
-1,  16388,  16388, 4096, 8192, 0x03640b38
-2,  16388,  16388, 4096, 8192, 0x1216e352
+1,  16388,  16388, 4096, 8192, 0xdea20516
+2,  16388,  16388, 4096, 8192, 0x7538f52b
 0,  4,  4,1,   32, 0xf3a3bf66
-- 
2.31.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 07/12] avradio/avformat/sdrdemux: Avoid uninitialized memory on mono -> stereo switch

2023-07-30 Thread Michael Niedermayer
Signed-off-by: Michael Niedermayer 
---
 libavformat/sdrdemux.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/libavformat/sdrdemux.c b/libavformat/sdrdemux.c
index 69349add7b..8f0f4657f3 100644
--- a/libavformat/sdrdemux.c
+++ b/libavformat/sdrdemux.c
@@ -1150,6 +1150,8 @@ static int demodulate_fm(SDRContext *sdr, Station 
*station, AVStream *st, AVPack
 sst->out_buf[2*i+0] = m + q;
 sst->out_buf[2*i+1] = m - q;
 } else {
+newbuf[2*i+1] = 0;
+
 sst->out_buf[2*i+0] =
 sst->out_buf[2*i+1] = m;
 }
-- 
2.31.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 11/12] avradio/avformat/sdrdemux: fix FM block size

2023-07-30 Thread Michael Niedermayer
as we copied twice the bandwith needed previously, we now also
need only half the block size.
Done in a seperate patch for easier bisection

Signed-off-by: Michael Niedermayer 
---
 libavformat/sdrdemux.c |  2 +-
 tests/ref/fate/sdr-fm  | 12 ++--
 2 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/libavformat/sdrdemux.c b/libavformat/sdrdemux.c
index a40346ff31..bda7387213 100644
--- a/libavformat/sdrdemux.c
+++ b/libavformat/sdrdemux.c
@@ -1692,7 +1692,7 @@ int avpriv_sdr_common_init(AVFormatContext *s)
 sdr->fm_bandwidth_p2 =  16.5 * 1000; // Officially Stereo Broadcast FM has 
15khz audio bandwidth
 
 sdr->am_block_size= find_block_size(sdr, sdr->am_bandwidth / 2);
-sdr->fm_block_size= find_block_size(sdr, sdr->fm_bandwidth);
+sdr->fm_block_size= find_block_size(sdr, sdr->fm_bandwidth / 2);
 sdr->fm_block_size_p2 = find_block_size(sdr, sdr->fm_bandwidth_p2);
 
 sdr->windowed_block = av_malloc(sizeof(*sdr->windowed_block) * 2 * 
sdr->block_size);
diff --git a/tests/ref/fate/sdr-fm b/tests/ref/fate/sdr-fm
index 97a2320a2a..ef76e4f584 100644
--- a/tests/ref/fate/sdr-fm
+++ b/tests/ref/fate/sdr-fm
@@ -15,11 +15,11 @@
 #channel_layout_name 2: stereo
 0,  0,  0,1,   32, 0xf553af75
 0,  1,  1,1,   32, 0xeabc15b3
-1,   8196,   8196, 4096, 8192, 0x4af5090c
-2,   8196,   8196, 4096, 8192, 0x8e43fafd
-1,  12292,  12292, 4096, 8192, 0x39fbfe6a
-2,  12292,  12292, 4096, 8192, 0x7febfb59
+1,   8196,   8196, 4096, 8192, 0xdd0d10be
+2,   8196,   8196, 4096, 8192, 0x98c4f547
+1,  12292,  12292, 4096, 8192, 0xaf58fbdc
+2,  12292,  12292, 4096, 8192, 0x6d53f60a
 0,  3,  3,1,   32, 0xf8b7b144
-1,  16388,  16388, 4096, 8192, 0x886a05fe
-2,  16388,  16388, 4096, 8192, 0x0b2cf20d
+1,  16388,  16388, 4096, 8192, 0x03640b38
+2,  16388,  16388, 4096, 8192, 0x1216e352
 0,  4,  4,1,   32, 0xf3a3bf66
-- 
2.31.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 06/12] avradio/avformat/sdrdemux: run clip check on the correct samples

2023-07-30 Thread Michael Niedermayer
Signed-off-by: Michael Niedermayer 
---
 libavformat/sdrdemux.c | 7 +++
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/libavformat/sdrdemux.c b/libavformat/sdrdemux.c
index 44a6489bd2..69349add7b 100644
--- a/libavformat/sdrdemux.c
+++ b/libavformat/sdrdemux.c
@@ -1153,10 +1153,9 @@ static int demodulate_fm(SDRContext *sdr, Station 
*station, AVStream *st, AVPack
 sst->out_buf[2*i+0] =
 sst->out_buf[2*i+1] = m;
 }
-
-if (fabs(sst->out_buf[i]) > clip) {
-av_log(sdr->avfmt, AV_LOG_WARNING, "CLIP %f\n", sst->out_buf[i]);
-clip = fabs(sst->out_buf[i]) * 1.1;
+if (fmax(fabs(sst->out_buf[2*i+0]), fabs(sst->out_buf[2*i+1])) > clip) 
{
+av_log(sdr->avfmt, AV_LOG_WARNING, "CLIP %f %f\n", 
sst->out_buf[2*i+0], sst->out_buf[2*i+1]);
+clip = fmax(fabs(sst->out_buf[2*i+0]), fabs(sst->out_buf[2*i+1])) 
* 1.1;
 }
 }
 
-- 
2.31.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 10/12] avradio/avformat/sdrdemux: fix off by 2 FM bandwidth error

2023-07-30 Thread Michael Niedermayer
Also adjust related parameters

Signed-off-by: Michael Niedermayer 
---
 libavformat/sdrdemux.c |  8 
 tests/ref/fate/sdr-am  | 25 -
 tests/ref/fate/sdr-fm  | 14 +++---
 3 files changed, 23 insertions(+), 24 deletions(-)

diff --git a/libavformat/sdrdemux.c b/libavformat/sdrdemux.c
index 0e327f4860..a40346ff31 100644
--- a/libavformat/sdrdemux.c
+++ b/libavformat/sdrdemux.c
@@ -704,7 +704,7 @@ static int demodulate_am(SDRContext *sdr, Station *station, 
AVStream *st, AVPack
 double freq= station->frequency;
 int64_t bandwidth = station->bandwidth;
 int index = lrint(F2INDEX(freq));
-int len   = (bandwidth * 2ll * sdr->block_size + sdr->sdr_sample_rate/2) / 
sdr->sdr_sample_rate;
+int len   = (bandwidth * 1ll * sdr->block_size + sdr->sdr_sample_rate/2) / 
sdr->sdr_sample_rate;
 float *newbuf;
 float scale;
 int sample_rate = sdr->sdr_sample_rate * (int64_t)sdr->am_block_size / 
sdr->block_size;
@@ -1030,7 +1030,7 @@ static int demodulate_fm(SDRContext *sdr, Station 
*station, AVStream *st, AVPack
 double freq= station->frequency;
 int64_t bandwidth = station->bandwidth;
 int index = lrint(F2INDEX(freq));
-int len   = (bandwidth * 2ll * sdr->block_size + sdr->sdr_sample_rate/2) / 
sdr->sdr_sample_rate;
+int len   = (bandwidth * 1ll * sdr->block_size + sdr->sdr_sample_rate/2) / 
sdr->sdr_sample_rate;
 float *newbuf;
 float scale;
 int sample_rate= sdr->sdr_sample_rate * (int64_t)sdr->fm_block_size
/ sdr->block_size;
@@ -1687,11 +1687,11 @@ int avpriv_sdr_common_init(AVFormatContext *s)
 av_log(s, AV_LOG_INFO, "Block size %d\n", sdr->block_size);
 
 sdr->block_time = sdr->block_size / (double)sdr->sdr_sample_rate;
-sdr->am_bandwidth=   6   * 1000;
+sdr->am_bandwidth=  12   * 1000;
 sdr->fm_bandwidth= 180   * 1000;
 sdr->fm_bandwidth_p2 =  16.5 * 1000; // Officially Stereo Broadcast FM has 
15khz audio bandwidth
 
-sdr->am_block_size= find_block_size(sdr, sdr->am_bandwidth);
+sdr->am_block_size= find_block_size(sdr, sdr->am_bandwidth / 2);
 sdr->fm_block_size= find_block_size(sdr, sdr->fm_bandwidth);
 sdr->fm_block_size_p2 = find_block_size(sdr, sdr->fm_bandwidth_p2);
 
diff --git a/tests/ref/fate/sdr-am b/tests/ref/fate/sdr-am
index e2ae353902..992ec1936d 100644
--- a/tests/ref/fate/sdr-am
+++ b/tests/ref/fate/sdr-am
@@ -30,18 +30,17 @@
 #channel_layout_name 5: stereo
 0,  0,  0,1,   32, 0x816a0964
 0,  1,  1,1,   32, 0x140ce2da
-1,   2048,   2048, 1024, 2048, 0x4d31ff0f
-2,   2048,   2048, 1024, 2048, 0x3cd002ad
-3,   2048,   2048, 1024, 2048, 0x8bdd034d
-4,   2048,   2048, 1024, 2048, 0xc6430169
-1,   3072,   3072, 1024, 2048, 0xb307000d
-2,   3072,   3072, 1024, 2048, 0x3f6d01d4
-3,   3072,   3072, 1024, 2048, 0x2de9fde9
-4,   3072,   3072, 1024, 2048, 0xad7efe6f
+1,   2048,   2048, 1024, 2048, 0x3cd002ad
+2,   2048,   2048, 1024, 2048, 0x8bdd034d
+3,   2048,   2048, 1024, 2048, 0xc6430169
+1,   3072,   3072, 1024, 2048, 0x3f6d01d4
+2,   3072,   3072, 1024, 2048, 0x2de9fde9
+3,   3072,   3072, 1024, 2048, 0xad7efe6f
+4,   3072,   3072, 1024, 2048, 0x2c18fef7
 5,   3072,   3072, 1024, 2048, 0x9c840168
-1,   4096,   4096, 1024, 2048, 0x7e7cfe03
-2,   4096,   4096, 1024, 2048, 0x6561fc7b
-3,   4096,   4096, 1024, 2048, 0xdcd6ff8d
-4,   4096,   4096, 1024, 2048, 0xedac0493
+1,   4096,   4096, 1024, 2048, 0x6561fc7b
+2,   4096,   4096, 1024, 2048, 0xdcd6ff8d
+3,   4096,   4096, 1024, 2048, 0xedac0493
+4,   4096,   4096, 1024, 2048, 0x7e7cfe03
 5,   4096,   4096, 1024, 2048, 0x970a0066
-0,  3,  3,1,   32, 0x6ea8fa49
+0,  3,  3,1,   32, 0x76d901a2
diff --git a/tests/ref/fate/sdr-fm b/tests/ref/fate/sdr-fm
index 3ae5adc2c0..97a2320a2a 100644
--- a/tests/ref/fate/sdr-fm
+++ b/tests/ref/fate/sdr-fm
@@ -15,11 +15,11 @@
 #channel_layout_name 2: stereo
 0,  0,  0,1,   32, 0xf553af75
 0,  1,  1,1,   32, 0xeabc15b3
-1,   8196,   8196, 4096, 8192, 0x585d090e
-2,   8196,   8196, 4096, 8192, 0xb966fb19
-1,  12292,  12292, 4096, 8192, 0x6d8ffe6e
-2,  12292,  12292, 4096, 8192, 0x51d1fb50
+1,   8196,   8196, 4096, 8192, 0x4af5090c
+2,   8196,   8196, 4096, 8192, 0x8e43fafd
+1,  12292,  12292, 4096, 8192, 0x39fbfe6a
+2,  12292,  12292, 4096, 8192, 0x7febfb59
 0,   

[FFmpeg-devel] [PATCH 09/12] avradio/avformat/sdrdemux: dont use a fuction name as local variable

2023-07-30 Thread Michael Niedermayer
Signed-off-by: Michael Niedermayer 
---
 libavformat/sdrdemux.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/libavformat/sdrdemux.c b/libavformat/sdrdemux.c
index 3f3390049c..0e327f4860 100644
--- a/libavformat/sdrdemux.c
+++ b/libavformat/sdrdemux.c
@@ -1043,13 +1043,13 @@ static int demodulate_fm(SDRContext *sdr, Station 
*station, AVStream *st, AVPack
 double carrier19_i_exact;
 int W= 5;
 double dc = 0, dcw = 0;
-int len2 = FFMIN(index, 2*sdr->block_size - index);
+int lenmax = FFMIN(index, 2*sdr->block_size - index);
 
 av_assert0(!st || (sst == station->stream && sst->station == station));
 
 //If only some of the bandwidth is available, just try with less
-if (len2 < len && len2 > len/2)
-len = len2;
+if (lenmax < len && lenmax > len/2)
+len = lenmax;
 
 if (index + len >= 2*sdr->block_size ||
 index - len < 0 ||
-- 
2.31.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 05/12] avradio/avformat/sdrdemux: delay station search on AGC adjust

2023-07-30 Thread Michael Niedermayer
Signed-off-by: Michael Niedermayer 
---
 libavformat/sdrdemux.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/libavformat/sdrdemux.c b/libavformat/sdrdemux.c
index fa45d30a3d..44a6489bd2 100644
--- a/libavformat/sdrdemux.c
+++ b/libavformat/sdrdemux.c
@@ -1536,6 +1536,8 @@ static void *soapy_needs_bigger_buffers_worker(SDRContext 
*sdr)
 int ret = sdr->set_gain_callback(sdr, wanted_gain);
 if (ret >= 0) {
 agc_gain = wanted_gain;
+if (block_counter)
+block_counter = 1;
 }
 }
 pthread_mutex_unlock(>mutex);
-- 
2.31.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 04/12] avradio/avformat/sdrdemux: only update agc_gain on success

2023-07-30 Thread Michael Niedermayer
Signed-off-by: Michael Niedermayer 
---
 libavformat/sdrdemux.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/libavformat/sdrdemux.c b/libavformat/sdrdemux.c
index e5ee4e80f5..fa45d30a3d 100644
--- a/libavformat/sdrdemux.c
+++ b/libavformat/sdrdemux.c
@@ -1533,8 +1533,10 @@ static void 
*soapy_needs_bigger_buffers_worker(SDRContext *sdr)
 fabs(wanted_gain - agc_gain) > 0.001 &&
 sdr->set_gain_callback
 ) {
-sdr->set_gain_callback(sdr, wanted_gain);
-agc_gain = wanted_gain;
+int ret = sdr->set_gain_callback(sdr, wanted_gain);
+if (ret >= 0) {
+agc_gain = wanted_gain;
+}
 }
 pthread_mutex_unlock(>mutex);
 
-- 
2.31.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 03/12] avradio/avdevice/sdrindev: Soapy / RTLSDR ignores gain in direct sampling mode

2023-07-30 Thread Michael Niedermayer
Signed-off-by: Michael Niedermayer 
---
 libavdevice/sdrindev.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/libavdevice/sdrindev.c b/libavdevice/sdrindev.c
index f07bd6b154..8766fc2f34 100644
--- a/libavdevice/sdrindev.c
+++ b/libavdevice/sdrindev.c
@@ -88,6 +88,10 @@ static int sdrindev_set_gain_callback(SDRContext *sdr, float 
gain)
 }
 
 if (sdr->sdr_gain != GAIN_SDR_AGC) {
+if (sdr->current_direct_samp && !strcmp(sdr->current_direct_samp, 
"2")) {
+return -1; // soapy ignores gain in direct sampling mode
+}
+
 ret = SoapySDRDevice_setGain(soapy, SOAPY_SDR_RX, 0, gain);
 if (ret) {
 av_log(avfmt, AV_LOG_WARNING, "Failed to set gain to %f 
(%s)\n", gain, SoapySDRDevice_lastError());
-- 
2.31.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 02/12] avradio/avformat/sdrdemux: Move Software AGC into buffer thread

2023-07-30 Thread Michael Niedermayer
This allows the AGC to act with less latency

Signed-off-by: Michael Niedermayer 
---
 libavformat/sdr.h  |  1 -
 libavformat/sdrdemux.c | 77 --
 2 files changed, 44 insertions(+), 34 deletions(-)

diff --git a/libavformat/sdr.h b/libavformat/sdr.h
index 1f2d3a49ab..1bf8fbef79 100644
--- a/libavformat/sdr.h
+++ b/libavformat/sdr.h
@@ -161,7 +161,6 @@ typedef struct SDRContext {
 float agc_max_headroom;
 float agc_max_headroom_time;
 int agc_low_time;
-atomic_int wanted_gain;
 int sdr_adcc;
 int64_t bandwidth;
 int64_t last_pts;
diff --git a/libavformat/sdrdemux.c b/libavformat/sdrdemux.c
index 4bde431e17..e5ee4e80f5 100644
--- a/libavformat/sdrdemux.c
+++ b/libavformat/sdrdemux.c
@@ -1475,6 +1475,7 @@ static void *soapy_needs_bigger_buffers_worker(SDRContext 
*sdr)
 unsigned block_counter = 0;
 int64_t local_wanted_freq = 0;
 int64_t last_wanted_freq = 0;
+float wanted_gain = (sdr->min_gain + sdr->max_gain) / 2;
 float agc_gain = 0;
 
 sdr->remaining_file_block_size = 0;
@@ -1485,7 +1486,6 @@ static void *soapy_needs_bigger_buffers_worker(SDRContext 
*sdr)
 FIFOElement fifo_element;
 int remaining, ret;
 int empty_blocks, full_blocks;
-float wanted_gain = atomic_load(>wanted_gain) / 65536.0;
 int64_t wanted_freq = atomic_load(>wanted_freq);
 int seek_direction = atomic_load(>seek_direction);
 
@@ -1551,6 +1551,49 @@ static void 
*soapy_needs_bigger_buffers_worker(SDRContext *sdr)
 remaining -= ret;
 }
 
+if (sdr->sdr_gain == GAIN_SW_AGC) {
+float inmax = 0;
+int inmax1 = 0;
+// We only check 25% of the data to safe computations
+int start = 3*sdr->block_size / 4;
+int end   = 5*sdr->block_size / 4;
+if (sdr->sample_size == 2) {
+const int8_t *halfblock = fifo_element.halfblock;
+for (int i = start; i < end; i++) {
+int v = FFMAX(FFABS(halfblock[i]), FFABS(halfblock[i]));
+inmax1 = FFMAX(inmax1, v);
+}
+} else if (sdr->sample_size == 4) {
+const int16_t *halfblock = fifo_element.halfblock;
+for (int i = start; i < end; i++) {
+int v = FFMAX(FFABS(halfblock[i]), FFABS(halfblock[i]));
+inmax1 = FFMAX(inmax1, v);
+}
+} else {
+const float *halfblock = fifo_element.halfblock;
+for (int i = start; i < end; i++) {
+float v = fmaxf(fabsf(halfblock[i]), fabsf(halfblock[i]));
+inmax = fmaxf(inmax, v);
+}
+}
+inmax = fmaxf(inmax, inmax1 / sdr->sample_scale);
+
+if (inmax > 1.0 - sdr->agc_min_headroom && wanted_gain > 
sdr->min_gain) {
+//according to docs this is a dB scale, in reality it beheaves 
differnt to that
+//Because of this we will try to just make small changes and 
not assume too much
+wanted_gain = FFMIN(wanted_gain, FFMAX(agc_gain - 1.0, 
agc_gain * 0.9));
+
+sdr->agc_low_time = 0;
+} else if (inmax < 1.0 - sdr->agc_max_headroom && wanted_gain < 
sdr->max_gain) {
+sdr->agc_low_time += sdr->block_size;
+if (sdr->agc_low_time > sdr->agc_max_headroom_time * 
sdr->sdr_sample_rate) {
+sdr->agc_low_time = 0;
+wanted_gain = FFMAX(wanted_gain, FFMIN(agc_gain + 1.0, 
agc_gain * 1.1));
+}
+} else
+sdr->agc_low_time = 0;
+}
+
 inject_block_into_fifo(sdr, sdr->full_block_fifo, _element, 
"block fifo overflow, discarding block\n");
 }
 av_assert0(atomic_load(>close_requested) == 1);
@@ -1724,7 +1767,6 @@ int avpriv_sdr_common_init(AVFormatContext *s)
 atomic_init(>close_requested, 0);
 atomic_init(>seek_direction, 0);
 atomic_init(>wanted_freq, sdr->user_wanted_freq);
-atomic_init(>wanted_gain, lrint((sdr->min_gain + sdr->max_gain) * 
65536 / 2));
 ret = pthread_mutex_init(>mutex, NULL);
 if (ret) {
 av_log(s, AV_LOG_ERROR, "pthread_mutex_init failed: %s\n", 
strerror(ret));
@@ -2021,37 +2063,6 @@ process_next_block:
 }
 }
 
-float smaller_block_gain = FFMIN(fifo_element[0].gain, 
fifo_element[1].gain);
-float  bigger_block_gain = FFMAX(fifo_element[0].gain, 
fifo_element[1].gain);
-
-if (sdr->sdr_gain == GAIN_SW_AGC) {
-float inmax = 0;
-float wanted_gain = atomic_load(>wanted_gain) / 65536.0;
-// We only check 25% of the data to safe computations
-int start = 3*sdr->block_size / 4;
-int end   = 5*sdr->block_size / 4;
-for (i = start; i < end; i++) {
-float v = fmaxf(fabsf(sdr->windowed_block[i].re), 

[FFmpeg-devel] [PATCH 01/12] avradio/avformat/sdrdemux: Move agc_gain into local variable

2023-07-30 Thread Michael Niedermayer
Signed-off-by: Michael Niedermayer 
---
 libavformat/sdr.h  | 1 -
 libavformat/sdrdemux.c | 7 ---
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/libavformat/sdr.h b/libavformat/sdr.h
index 77278ada67..1f2d3a49ab 100644
--- a/libavformat/sdr.h
+++ b/libavformat/sdr.h
@@ -161,7 +161,6 @@ typedef struct SDRContext {
 float agc_max_headroom;
 float agc_max_headroom_time;
 int agc_low_time;
-float agc_gain; ///< current gain, should be 
accessed only by buffer thread after init
 atomic_int wanted_gain;
 int sdr_adcc;
 int64_t bandwidth;
diff --git a/libavformat/sdrdemux.c b/libavformat/sdrdemux.c
index 0dc89041c5..4bde431e17 100644
--- a/libavformat/sdrdemux.c
+++ b/libavformat/sdrdemux.c
@@ -1475,6 +1475,7 @@ static void *soapy_needs_bigger_buffers_worker(SDRContext 
*sdr)
 unsigned block_counter = 0;
 int64_t local_wanted_freq = 0;
 int64_t last_wanted_freq = 0;
+float agc_gain = 0;
 
 sdr->remaining_file_block_size = 0;
 
@@ -1529,16 +1530,16 @@ static void 
*soapy_needs_bigger_buffers_worker(SDRContext *sdr)
 block_counter = 0; // we just changed the frequency, do not trust 
the next blocks content
 }
 if (sdr->sdr_gain == GAIN_SW_AGC &&
-fabs(wanted_gain - sdr->agc_gain) > 0.001 &&
+fabs(wanted_gain - agc_gain) > 0.001 &&
 sdr->set_gain_callback
 ) {
 sdr->set_gain_callback(sdr, wanted_gain);
-sdr->agc_gain = wanted_gain;
+agc_gain = wanted_gain;
 }
 pthread_mutex_unlock(>mutex);
 
 fifo_element.center_frequency = block_counter > 0 ? sdr->freq : 0;
-fifo_element.gain = sdr->agc_gain; //we make only small 
changes so slightly mixing should be ok
+fifo_element.gain = agc_gain; //we make only small changes 
so slightly mixing should be ok
 
 remaining = sdr->block_size;
 while (remaining && !atomic_load(>close_requested)) {
-- 
2.31.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".


Re: [FFmpeg-devel] What is FFmpeg and what should it be

2023-07-30 Thread Nicolas George
Kieran Kunhya (12023-07-30):
> I plan to write a more detailed response to Nicolas' email. However,
> this response is superb because it immediately points out the flaw in
> the arguments. Users will not tolerate "incomplete" features, they
> will always want their edge case (packet capture replay) to work. This
> is Open Source, there are no product managers and roadmaps to
> constrain user requests so we have to decide as a community what is in
> scope and what is not.

“Patch welcome.”

And IF it becomes too big, we can discuss splitting it into a separate
library.

But as long as a new feature doesn't metastasize into the common code,
as long as it stays optional, there is no ground to oppose it, imaginary
“scope” or not.

Regards,

-- 
  Nicolas George


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] What is FFmpeg and what should it be

2023-07-30 Thread Kieran Kunhya
On Sun, Jul 30, 2023 at 6:07 PM Andrey Turkin  wrote:
>
> вс, 30 июл. 2023 г. в 16:04, Nicolas George :
>
> > Kieran Kunhya (12023-07-28):
> > > FFmpeg doesn't implement TCP in userspace, it doesn't implement the
> > > WiFi protocol etc etc. Different layers are delegated to different
> > > programs.
> >
>
> There is a good reason to have some part of TCP implemented in FFmpeg
> though. It would be _extremely_ useful to be able to read and replay pcap
> dumps of an RTP stream, or an HLS or DASH stream, or whichever else
> multi-connection streams are there.

I plan to write a more detailed response to Nicolas' email. However,
this response is superb because it immediately points out the flaw in
the arguments. Users will not tolerate "incomplete" features, they
will always want their edge case (packet capture replay) to work. This
is Open Source, there are no product managers and roadmaps to
constrain user requests so we have to decide as a community what is in
scope and what is not.

Kieran
___
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] What is FFmpeg and what should it be

2023-07-30 Thread Andrey Turkin
вс, 30 июл. 2023 г. в 16:04, Nicolas George :

> Kieran Kunhya (12023-07-28):
> > FFmpeg doesn't implement TCP in userspace, it doesn't implement the
> > WiFi protocol etc etc. Different layers are delegated to different
> > programs.
>

There is a good reason to have some part of TCP implemented in FFmpeg
though. It would be _extremely_ useful to be able to read and replay pcap
dumps of an RTP stream, or an HLS or DASH stream, or whichever else
multi-connection streams are there.
There is also at least one demodulator already in FFmpeg, namely VBI bit
slicer (it is implemented through an external library though).
___
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/2] avcodec/cbs: Add specialization for ff_cbs_(read|write)_unsigned()

2023-07-30 Thread Andreas Rheinhardt
Andreas Rheinhardt:
> These functions allow not only to read and write unsigned values,
> but also to check ranges and to emit trace output which can be
> beautified when processing arrays (indices like "[i]" are replaced
> by their actual numbers).
> 
> Yet lots of callers actually only need something simpler:
> Their range is only implicitly restricted by the amount
> of bits used and they are not part of arrays, hence don't
> need this beautification.
> 
> This commit adds specializations for these callers;
> this is very beneficial size-wise (it reduced the size
> of .text by 14928 bytes here), as a call is now cheaper.
> 
> Signed-off-by: Andreas Rheinhardt 
> ---
>  libavcodec/cbs.c  | 34 ++
>  libavcodec/cbs_av1.c  | 28 +++-
>  libavcodec/cbs_h2645.c| 15 +--
>  libavcodec/cbs_internal.h | 11 ++-
>  libavcodec/cbs_mpeg2.c| 15 +--
>  libavcodec/cbs_vp9.c  | 14 --
>  6 files changed, 97 insertions(+), 20 deletions(-)
> 
> diff --git a/libavcodec/cbs.c b/libavcodec/cbs.c
> index e829caa0a0..8bd63aa831 100644
> --- a/libavcodec/cbs.c
> +++ b/libavcodec/cbs.c
> @@ -536,10 +536,13 @@ void ff_cbs_trace_syntax_element(CodedBitstreamContext 
> *ctx, int position,
> position, name, pad, bits, value);
>  }
>  
> -int ff_cbs_read_unsigned(CodedBitstreamContext *ctx, GetBitContext *gbc,
> - int width, const char *name,
> - const int *subscripts, uint32_t *write_to,
> - uint32_t range_min, uint32_t range_max)
> +static av_always_inline int cbs_read_unsigned(CodedBitstreamContext *ctx,
> +  GetBitContext *gbc,
> +  int width, const char *name,
> +  const int *subscripts,
> +  uint32_t *write_to,
> +  uint32_t range_min,
> +  uint32_t range_max)
>  {
>  uint32_t value;
>  int position;
> @@ -579,6 +582,22 @@ int ff_cbs_read_unsigned(CodedBitstreamContext *ctx, 
> GetBitContext *gbc,
>  return 0;
>  }
>  
> +int ff_cbs_read_unsigned(CodedBitstreamContext *ctx, GetBitContext *gbc,
> + int width, const char *name,
> + const int *subscripts, uint32_t *write_to,
> + uint32_t range_min, uint32_t range_max)
> +{
> +return cbs_read_unsigned(ctx, gbc, width, name, subscripts,
> + write_to, range_min, range_max);
> +}
> +
> +int ff_cbs_read_simple_unsigned(CodedBitstreamContext *ctx, GetBitContext 
> *gbc,
> +int width, const char *name, uint32_t 
> *write_to)
> +{
> +return cbs_read_unsigned(ctx, gbc, width, name, NULL,
> + write_to, 0, UINT32_MAX);
> +}
> +
>  int ff_cbs_write_unsigned(CodedBitstreamContext *ctx, PutBitContext *pbc,
>int width, const char *name,
>const int *subscripts, uint32_t value,
> @@ -615,6 +634,13 @@ int ff_cbs_write_unsigned(CodedBitstreamContext *ctx, 
> PutBitContext *pbc,
>  return 0;
>  }
>  
> +int ff_cbs_write_simple_unsigned(CodedBitstreamContext *ctx, PutBitContext 
> *pbc,
> + int width, const char *name, uint32_t value)
> +{
> +return ff_cbs_write_unsigned(ctx, pbc, width, name, NULL,
> + value, 0, MAX_UINT_BITS(width));
> +}
> +
>  int ff_cbs_read_signed(CodedBitstreamContext *ctx, GetBitContext *gbc,
> int width, const char *name,
> const int *subscripts, int32_t *write_to,
> diff --git a/libavcodec/cbs_av1.c b/libavcodec/cbs_av1.c
> index 1229480567..114d8580b3 100644
> --- a/libavcodec/cbs_av1.c
> +++ b/libavcodec/cbs_av1.c
> @@ -412,9 +412,8 @@ static int cbs_av1_read_subexp(CodedBitstreamContext 
> *ctx, GetBitContext *gbc,
>  }
>  
>  if (len < max_len) {
> -err = ff_cbs_read_unsigned(ctx, gbc, range_bits,
> -   "subexp_bits", NULL, ,
> -   0, MAX_UINT_BITS(range_bits));
> +err = ff_cbs_read_simple_unsigned(ctx, gbc, range_bits,
> +  "subexp_bits", );
>  if (err < 0)
>  return err;
>  
> @@ -476,10 +475,9 @@ static int cbs_av1_write_subexp(CodedBitstreamContext 
> *ctx, PutBitContext *pbc,
>  return err;
>  
>  if (len < max_len) {
> -err = ff_cbs_write_unsigned(ctx, pbc, range_bits,
> -"subexp_bits", NULL,
> -value - range_offset,
> -0, MAX_UINT_BITS(range_bits));
> +err = 

Re: [FFmpeg-devel] [PATCH] avcodec/h264_slice: Remove always-false check

2023-07-30 Thread Andreas Rheinhardt
Andreas Rheinhardt:
> The H.264 decoder, the only codec with which this code
> is ever called, does not set AVCodec.pix_fmts.
> 
> Signed-off-by: Andreas Rheinhardt 
> ---
>  libavcodec/h264_slice.c | 14 +-
>  1 file changed, 5 insertions(+), 9 deletions(-)
> 
> diff --git a/libavcodec/h264_slice.c b/libavcodec/h264_slice.c
> index 6f0a7c1fb7..58fe245891 100644
> --- a/libavcodec/h264_slice.c
> +++ b/libavcodec/h264_slice.c
> @@ -797,8 +797,6 @@ static enum AVPixelFormat get_pixel_format(H264Context 
> *h, int force_callback)
>   CONFIG_H264_VIDEOTOOLBOX_HWACCEL + \
>   CONFIG_H264_VDPAU_HWACCEL)
>  enum AVPixelFormat pix_fmts[HWACCEL_MAX + 2], *fmt = pix_fmts;
> -const enum AVPixelFormat *choices = pix_fmts;
> -int i;
>  
>  switch (h->ps.sps->bit_depth_luma) {
>  case 9:
> @@ -883,9 +881,7 @@ static enum AVPixelFormat get_pixel_format(H264Context 
> *h, int force_callback)
>  #if CONFIG_H264_VAAPI_HWACCEL
>  *fmt++ = AV_PIX_FMT_VAAPI;
>  #endif
> -if (h->avctx->codec->pix_fmts)
> -choices = h->avctx->codec->pix_fmts;
> -else if (h->avctx->color_range == AVCOL_RANGE_JPEG)
> +if (h->avctx->color_range == AVCOL_RANGE_JPEG)
>  *fmt++ = AV_PIX_FMT_YUVJ420P;
>  else
>  *fmt++ = AV_PIX_FMT_YUV420P;
> @@ -899,10 +895,10 @@ static enum AVPixelFormat get_pixel_format(H264Context 
> *h, int force_callback)
>  
>  *fmt = AV_PIX_FMT_NONE;
>  
> -for (i=0; choices[i] != AV_PIX_FMT_NONE; i++)
> -if (choices[i] == h->avctx->pix_fmt && !force_callback)
> -return choices[i];
> -return ff_thread_get_format(h->avctx, choices);
> +for (int i = 0; pix_fmts[i] != AV_PIX_FMT_NONE; i++)
> +if (pix_fmts[i] == h->avctx->pix_fmt && !force_callback)
> +return pix_fmts[i];
> +return ff_thread_get_format(h->avctx, pix_fmts);
>  }
>  
>  /* export coded and cropped frame dimensions to AVCodecContext */

Forgot about this one. Will apply it tonight unless there are objections.

- 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] What is FFmpeg and what should it be

2023-07-30 Thread Nicolas George
Kieran Kunhya (12023-07-28):
> FFmpeg doesn't implement TCP in userspace, it doesn't implement the
> WiFi protocol etc etc. Different layers are delegated to different
> programs.

Hi. You seem to be discussing this in more good faith than I previously
imagined, so I will try to tone done the irritation in my mails.

I am also changing the subject of the mail, so that more people will
have a look at it. I have already posted about my conception of what
FFmpeg is and should be in the previous mail:
http://ffmpeg.org/pipermail/ffmpeg-devel/2023-July/312735.html

There are at least two necessary conditions for something to go into
FFmpeg: that it is useful to users, at least a few of them, and that
somebody bothered to write the code.

FFmpeg is designed to run under an operating system, where a network
stack is usually available whenever network hardware exists, so there is
absolutely no need for that in FFmpeg.

But if people started to routinely use FFmpeg on some kind of
bare-metal microcontroller where network hardware exists but the
official network stack is too big to share the space with FFmpeg, and if
somebody were to propose a limited network stack based on lavu's
cryptographic primitives, then it would totally make sense to accept it.

Yes, this example is far-fetched, because you chose a case where only a
far-fetched example works.

You insist on having different layers, and I agree it is somewhat
relevant. But remember: the Internet is not built on the nice
theoretical layers of the OSI model. The protocols of Internet are much
more messy, because they insist more on pragmatism than aesthetics, and
that is what made their success.

If there are well-defined layers, then probably the others layers are
already implemented, the “different programs” exist, are very
satisfactory and very widely available. Then FFmpeg does not need to
have them natively.

But if these “different programs” for different layers do not exist, or
are not satisfactory, or are not widely available, then we have to
develop them.

And if that happens, it would be idiot to force them to be separate
projects. Maybe later, when they have become stable, and other programs
use them, it will make sense to split them into their own separate
project. But in the beginning, it is a waste of effort.

> Is FFmpeg going to implement HTTP3 (QUIC) in full? QUIC is a layered protocol.

I do not know. I have followed things from afar, does HTTP3 brings
benefits from users, apart from more efficient tracking and faster
delivery of ads?

Anyway, your sentence brigs a point that is very important:

*** IT DOES NOT HAVE TO BE COMPLETE TO BE USEFUL. ***

See below for more about it.


> All of your examples are small and self-contained. SDR is definitely
> not small and self-contained. It's a field bigger than multimedia and
> there are many layers of framing inside.

Michael's code seems pretty self-contained to me.

And once again:

*** IT DOES NOT HAVE TO BE COMPLETE TO BE USEFUL. ***

As far as I understand it, if I bought the hardware tomorrow, the code
that Michael already wrote, and that is a tiny little bit of the whole
field of SDR, would already bring me features that are not available in
any other piece of Libre Software, or possibly at the cost of fragile
plumbing.

This is enough of an argument to warrant inclusion.

And it does not make sense to insist that one of our most talented
developers waste his time with the trouble of maintaining a separate
project just to satisfy aesthetic considerations of “proper layering”.

I have another example of “it does not have to be complete to be
useful”: XML. The whole XML standard is quite complex, it involves DVD
and schema validation, loading external entities, etc. But the use of
XML in multimedia is much more limited, it only involves parsing
“”-style text.

Now, “proper layering” dictates using a real XML library. But real XML
libraries are designed to support most of the standard, and that affects
their design as a whole.

That means every time we use a real XML library to parse
“”, we pay the price for the complexity of the whole
language, in terms of efficiency, reliability, security exposure.

If we had our own parser for “”, we would have to pay a
price only once.

“Proper layering” has benefits, but it also has costs. Therefore it is a
bad idea to adhere to it dogmatically.

FFmpeg has been successful because it relied on pragmatism rather than
dogmatic adherence to principles. Let us continue that way.

Regards,

-- 
  Nicolas George


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".