From patchwork Mon Jul 17 00:26:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 42775 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:6da1:b0:131:a7d0:bc6d with SMTP id gl33csp5078522pzb; Sun, 16 Jul 2023 17:27:29 -0700 (PDT) X-Google-Smtp-Source: APBJJlHmmAJeUETCVmSASOZDiE+Jtxw6DknV6/ikyrT6PxdS4e3QFR5iayWsx8ES40ZgvLDigDWy X-Received: by 2002:a17:906:73d9:b0:997:b843:7cb2 with SMTP id n25-20020a17090673d900b00997b8437cb2mr3250253ejl.60.1689553649526; Sun, 16 Jul 2023 17:27:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689553649; cv=none; d=google.com; s=arc-20160816; b=0c8VB/VQPZi78HZ9eEqMdyb4vfnrLIKSqG3LYunWwvpG55KzXsNN0AzArYx6ay+zSX WAe3ZRWviYpeRcXxqZ/7sc0OzpPTfISMgdvp3ISs8ZsIS6AnJ4UPeTmPNCeHbpcYlmYW bjt31ILdG1O0LidQTLcZpynEWL5u/RtQtskfeuh5TahYvxolXbe3P+ya6ueTK/IQqi7D smWoRPwh1Lz2IjPDTbOmmrqs7tIvCI9VLVm9hMoDZfCE8at+oRxcxM5uWAEBWKsXaoZy vnJtOj6uPKZz+Q5cgzHHaLWk0OxHzz73oHcYtTcv3H19Jp/QxVg3ooYd2uuoBq2TJLGk uIHg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:delivered-to; bh=df6o6s9/hi7ZornAjnFdRdOabpbqZgeNdpm+McXh0Bo=; fh=YYwLYmpaV0Fpw/rxmSKNRLS2XzDkAlGbHATiKOPtZrY=; b=MWiOJ9u+oLmUN195wy3xjHAtMw1MKZXKU4Ncz2POC9OR2ye2QolfBqS6uVldjluov0 JuIaThMSpF8KEyQ1HXnBEHNyFzTNwdSnIyBw1yjl0fa7WB8swrltXjQ4GPzbVKkxgE0F Ld6pb7O87zGVFOdigh9A1IG7gMbWw3GAQPrn17oGQ6RavopAJbHyVx/10WJRhmXnREwn MJOfmYsAzIuxVbR9JQOI0Z2DAI4RHQ8CCnM9fgJk06KOQC0F9dejwNHAk15xw6bDGefj 4Z2UMmgEi694KGH9jFZinvsRDuHKlvDCpIn47pe9zz00E1Jr2I7eqnhHS5Yfw2r+y/UV X/SA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id zo13-20020a170906ff4d00b0099318060d40si12439692ejb.459.2023.07.16.17.27.29; Sun, 16 Jul 2023 17:27:29 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1372A68C5D3; Mon, 17 Jul 2023 03:27:16 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: B2aBxFu7SwGn 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)