[FFmpeg-cvslog] [ffmpeg-radio] 06/14: avradio/sdrdemux: do not hack bandwidth value in random places

Michael Niedermayer ffmpeg-git at ffmpeg.org
Sat Jul 22 16:55:52 EEST 2023


This is an automated email from the git hooks/post-receive script.

Git pushed a commit to branch master
in repository libavradio.

commit 018370ac29f8451287d31875d489062dc62f8c12
Author:     Michael Niedermayer <michael at niedermayer.cc>
AuthorDate: Tue Jul 18 19:09:32 2023 +0200
Commit:     Michael Niedermayer <michael at niedermayer.cc>
CommitDate: Tue Jul 18 19:09:32 2023 +0200

    avradio/sdrdemux: do not hack bandwidth value in random places
    
    Instead do a basic check for totally invalid values during setup
    and warn the user for things that are still suspicious
    
    Bounding the value in the middle of the code would lead to
    growing complexity to consider that.
    Instead the code assumes now the value is correct after setup
    
    Signed-off-by: Michael Niedermayer <michael at niedermayer.cc>
---
 libavradio/sdrdemux.c   | 5 ++++-
 libavradio/sdrinradio.c | 2 +-
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/libavradio/sdrdemux.c b/libavradio/sdrdemux.c
index 07b43dec1c..c284f7d8d8 100644
--- a/libavradio/sdrdemux.c
+++ b/libavradio/sdrdemux.c
@@ -863,7 +863,7 @@ static int probe_fm(SDRContext *sdr)
     int half_bw_i = 200*1000 * (int64_t)sdr->block_size / sdr->sdr_sample_rate;
     int floor_bw_i = 10*1000 * (int64_t)sdr->block_size / sdr->sdr_sample_rate;
     float last_score[3] = {FLT_MAX, FLT_MAX, FLT_MAX};
-    int border_i = (sdr->sdr_sample_rate - FFMIN(sdr->bandwidth, sdr->sdr_sample_rate*7/8)) * sdr->block_size / sdr->sdr_sample_rate;
+    int border_i = (sdr->sdr_sample_rate - sdr->bandwidth) * sdr->block_size / sdr->sdr_sample_rate;
 
     if (2*half_bw_i > 2*sdr->block_size)
         return 0;
@@ -1516,6 +1516,9 @@ int ff_sdr_common_init(AVFormatContext *s)
     sdr->avfmt = s;
     s->ctx_flags |= AVFMTCTX_NOHEADER;
 
+    if (sdr->bandwidth > sdr->sdr_sample_rate * 7 / 8)
+        av_log(s, AV_LOG_WARNING, "Bandwidth looks suspicious\n");
+
     if (sdr->width>1 && sdr->height>1) {
         /* video stream */
         st = avformat_new_stream(s, NULL);
diff --git a/libavradio/sdrinradio.c b/libavradio/sdrinradio.c
index f824a1d190..d569842a9c 100644
--- a/libavradio/sdrinradio.c
+++ b/libavradio/sdrinradio.c
@@ -379,7 +379,7 @@ static int sdrindev_initial_hw_setup(AVFormatContext *s)
     sdr->bandwidth = SoapySDRDevice_getBandwidth(soapy, SOAPY_SDR_RX, 0);
 
     // rtlsdr doesnt return a valid value
-    if (!sdr->bandwidth)
+    if (!sdr->bandwidth || sdr->bandwidth >= sdr->sdr_sample_rate)
         sdr->bandwidth = sdr->sdr_sample_rate * 4 / 5;
     av_log(s, AV_LOG_INFO, "bandwidth %"PRId64"\n", sdr->bandwidth);
 



More information about the ffmpeg-cvslog mailing list