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 DB3F945EB2 for ; Mon, 17 Jul 2023 00:27:26 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id CD0BF68C58E; Mon, 17 Jul 2023 03:27:15 +0300 (EEST) Received: from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net [217.70.183.196]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D2C6968C4F3 for ; Mon, 17 Jul 2023 03:27:07 +0300 (EEST) Received: by mail.gandi.net (Postfix) with ESMTPSA id 1223BE0003 for ; Mon, 17 Jul 2023 00:27:06 +0000 (UTC) From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Mon, 17 Jul 2023 02:26:59 +0200 Message-Id: <20230717002704.3092192-2-michael@niedermayer.cc> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230717002704.3092192-1-michael@niedermayer.cc> References: <20230717002704.3092192-1-michael@niedermayer.cc> MIME-Version: 1.0 X-GND-Sasl: michael@niedermayer.cc Subject: [FFmpeg-devel] [PATCH 2/7] avradio/sdr: compensate for RTLSDR frequency limitations 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: Signed-off-by: Michael Niedermayer --- libavradio/sdr.h | 2 +- libavradio/sdrdemux.c | 9 ++++----- libavradio/sdrinradio.c | 10 ++++++++-- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/libavradio/sdr.h b/libavradio/sdr.h index ac6b7dffe0..dc20415457 100644 --- a/libavradio/sdr.h +++ b/libavradio/sdr.h @@ -210,7 +210,7 @@ typedef struct SDRContext { /** * Setup the hardware for the requested frequency */ - int (*set_frequency_callback)(struct SDRContext *sdr, int64_t frequency); + int64_t (*set_frequency_callback)(struct SDRContext *sdr, int64_t frequency); /** * Read from the hardware, block if nothing available with a reasonable timeout diff --git a/libavradio/sdrdemux.c b/libavradio/sdrdemux.c index a545e7cb4c..5a3af23a74 100644 --- a/libavradio/sdrdemux.c +++ b/libavradio/sdrdemux.c @@ -1129,11 +1129,10 @@ ModulationDescriptor ff_sdr_modulation_descs[] = { int ff_sdr_set_freq(SDRContext *sdr, int64_t freq) { freq = av_clip64(freq, sdr->min_center_freq, sdr->max_center_freq); - if (sdr->set_frequency_callback) { - int ret = sdr->set_frequency_callback(sdr, freq); - if (ret < 0) - return ret; + freq = sdr->set_frequency_callback(sdr, freq); + if (freq < 0) + return freq; } sdr->freq = freq; @@ -1421,7 +1420,7 @@ static void *soapy_needs_bigger_buffers_worker(SDRContext *sdr) if (sdr->seek_direction && block_counter > 5) { sdr->wanted_freq = snap2band(sdr, sdr->wanted_freq, sdr->seek_direction*sdr->bandwidth*0.5); } - if (sdr->wanted_freq != sdr->freq) { + if (fabs(sdr->wanted_freq - sdr->freq) > 1500) { //We could use a seperate MUTEX for the FIFO and for soapy ff_sdr_set_freq(sdr, sdr->wanted_freq); //This shouldnt really cause any problem if we just continue on error except that we continue returning data with the previous target frequency range diff --git a/libavradio/sdrinradio.c b/libavradio/sdrinradio.c index 0e7442fddf..f078d27e7b 100644 --- a/libavradio/sdrinradio.c +++ b/libavradio/sdrinradio.c @@ -68,7 +68,7 @@ static int sdrindev_read_callback(SDRContext *sdr, FIFOElement *fifo_element, in return ret; } -static int sdrindev_set_frequency_callback(SDRContext *sdr, int64_t freq) +static int64_t sdrindev_set_frequency_callback(SDRContext *sdr, int64_t freq) { AVFormatContext *avfmt = sdr->avfmt; SoapySDRDevice *soapy = sdr->soapy; @@ -83,6 +83,12 @@ static int sdrindev_set_frequency_callback(SDRContext *sdr, int64_t freq) } else sdr->current_direct_samp = value; } + //The R820T has a 16 bit fractional PLL which can do only multiplies of 439.45 + //Its more complex but this approximation works + //It has to be noted that SOAPY does not tell us about this, instead saopy + //pretends whatever we ask for we get exactly, but we dont + //For more details see: michelebavaro.blogspot.com/2014/05/gnss-carrier-phase-rtlsdr-and.html + freq = lrint(freq / 439.45) * 439.45; } if (SoapySDRDevice_setFrequency(soapy, SOAPY_SDR_RX, 0, freq, NULL) != 0) { @@ -90,7 +96,7 @@ static int sdrindev_set_frequency_callback(SDRContext *sdr, int64_t freq) return AVERROR_EXTERNAL; } } - return 0; + return freq; } static void print_and_free_list(AVFormatContext *s, char** names, size_t length, const char *title) -- 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".