From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 9B78540333 for ; Tue, 18 Jul 2023 21:46:35 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1744668C5B9; Wed, 19 Jul 2023 00:45:58 +0300 (EEST) Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id DE83868C58E for ; Wed, 19 Jul 2023 00:45:49 +0300 (EEST) Received: by mail.gandi.net (Postfix) with ESMTPSA id 4806740005 for ; Tue, 18 Jul 2023 21:45:48 +0000 (UTC) From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Tue, 18 Jul 2023 23:45:34 +0200 Message-Id: <20230718214542.685375-6-michael@niedermayer.cc> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230718214542.685375-1-michael@niedermayer.cc> References: <20230718214542.685375-1-michael@niedermayer.cc> MIME-Version: 1.0 X-GND-Sasl: michael@niedermayer.cc Subject: [FFmpeg-devel] [PATCH 06/14] avradio/sdrdemux: do not hack bandwidth value in random places X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: 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 --- 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); -- 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-request@ffmpeg.org with subject "unsubscribe".