From patchwork Fri Jul 7 17:22:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 42520 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:3b1e:b0:12b:9ae3:586d with SMTP id c30csp7449785pzh; Fri, 7 Jul 2023 10:22:49 -0700 (PDT) X-Google-Smtp-Source: APBJJlGZ/MKGYTnoGZWXWNHVX2ZZiXva6lrifzfNaeg53rwy5ASmaUurGVyFRgFKdyMtQoB5xajh X-Received: by 2002:a17:906:39da:b0:98d:ef34:c0c8 with SMTP id i26-20020a17090639da00b0098def34c0c8mr3723750eje.67.1688750569211; Fri, 07 Jul 2023 10:22:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688750569; cv=none; d=google.com; s=arc-20160816; b=r8Q1Y7TMSrbbc5DlM0th8zBW3eGJhDt2SLViseGTCOeCs7H+zPBML/Hea9aop3wecb yC3/aEHFagBejzmfjTKD1+XfVPpa4te8Wg0hcZPKr62NnsGhPhNNLq8P4B099vFP8eHI xqsSR6GyjZe8kZOxCSvfbw7U6XVnV4JB6g5Qq4WhL+dGBUnHci71AkxwFgdpO6IEziD8 B9lZH3k6+5PMAZXQ7sCTU9ojooqmF9Rujkys0NkA6DCvDnSWG26nEgir+bB/E5R/NTy7 qMJqSu2a5Hx3uWGCwED50T/Lnmk5hSFtDTJi8Y7Xrq7/+VDXnNmHb6Tiz+A+GJ4bA0y3 aR4w== 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=hU0c38ZP1N61IpGNqtxVzR4BKYOMF5vSZnH8FYiOiKk=; fh=YYwLYmpaV0Fpw/rxmSKNRLS2XzDkAlGbHATiKOPtZrY=; b=yRM90HfsT1SmQheVh3wyH4WlZveuyO7g8Qw91/KRh9juMXXMWwSgBrA9upGFryFxtr 2/ekUdZ3pvRdx2TmhRb012lk/ocoHIA4O1EkL/YjV1plONs+kT4+2F0MjeCiuWa81379 6Y1c/aYdsO7kMHvaDxz07n9XFDGEwsITKZzgXyOS0+zAauKRc1fKjgmiEh1KhOVUMWh8 Gqw5TtlYzZbR2ZKVj6m3PJDqMLcbxLoyti/n5cT7KWkrACtc09wiLdbM6bUjb4wcpy4+ 1vcnxMmb137fmqVvy3ydQU9mnUid0eKGgaeHp4Uj1njKxkXYIr7+nPII2tRTA735dzO7 uWRg== 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 pk28-20020a170906d7bc00b00991d54db2a6si2449442ejb.693.2023.07.07.10.22.48; Fri, 07 Jul 2023 10:22:49 -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 09ADA68C7A0; Fri, 7 Jul 2023 20:22:36 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A5F0868C618 for ; Fri, 7 Jul 2023 20:22:28 +0300 (EEST) X-GND-Sasl: michael@niedermayer.cc Received: by mail.gandi.net (Postfix) with ESMTPSA id 1971B1C0008 for ; Fri, 7 Jul 2023 17:22:27 +0000 (UTC) From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Fri, 7 Jul 2023 19:22:17 +0200 Message-Id: <20230707172224.2368067-2-michael@niedermayer.cc> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230707172224.2368067-1-michael@niedermayer.cc> References: <20230707172224.2368067-1-michael@niedermayer.cc> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/9] avradio/sdr: Consolidate candidate station entries 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: 4uPCS53GizmS also average frequcnies in candiddate station detections Signed-off-by: Michael Niedermayer --- libavradio/sdr.h | 1 + libavradio/sdrdemux.c | 45 ++++++++++++++++++++++++++++++++++++------- 2 files changed, 39 insertions(+), 7 deletions(-) diff --git a/libavradio/sdr.h b/libavradio/sdr.h index 4d6887a296..29465df0a1 100644 --- a/libavradio/sdr.h +++ b/libavradio/sdr.h @@ -70,6 +70,7 @@ typedef struct Station { char *name; enum Modulation modulation; double frequency; + int nb_frequency; ///< number of detections which are used to compute the frequency int64_t bandwidth; int64_t bandwidth_p2; float score; diff --git a/libavradio/sdrdemux.c b/libavradio/sdrdemux.c index 4ac360f71b..41eda615ae 100644 --- a/libavradio/sdrdemux.c +++ b/libavradio/sdrdemux.c @@ -150,6 +150,12 @@ static int find_station_enu(void *opaque, void *elem) return 0; } +static int free_station_enu(void *opaque, void *elem) +{ + free_station(elem); + return 0; +} + /** * Find stations within the given parameters. * @param[out] station_list array to return stations in @@ -218,15 +224,16 @@ static int create_station(SDRContext *sdr, Station *candidate_station) { Station *station_list[1000]; int nb_stations = find_stations(sdr, sdr->block_center_freq, sdr->sdr_sample_rate*0.5, station_list, FF_ARRAY_ELEMS(station_list)); + nb_candidate_match += candidate_station->nb_frequency - 1; for (i=0; ifrequency - freq); // Station already added, or we have 2 rather close stations if (modulation == station_list[i]->modulation && delta < freq_precission && station_list[i] != candidate_station) { - nb_candidate_match++; + nb_candidate_match += station_list[i]->nb_frequency; } if (modulation != station_list[i]->modulation && delta < (bandwidth + station_list[i]->bandwidth)/2.1) - nb_candidate_conflict++; + nb_candidate_conflict += station_list[i]->nb_frequency; } //if we have a recent conflict with an established station, skip this one if (conflict < CANDIDATE_STATION_TIMEOUT) @@ -355,20 +362,41 @@ static int create_candidate_station(SDRContext *sdr, enum Modulation modulation, Station *station; void *tmp; struct AVTreeNode *next = NULL; + Station *station_list[1000]; + double snapdistance = modulation == AM ? 5 : 50; + int nb_stations = find_stations(sdr, freq, snapdistance, station_list, FF_ARRAY_ELEMS(station_list)); + + if (nb_stations) { + for(int i = 1; imodulation != modulation || + (station_list[i]->modulation == modulation && + fabs(station_list[0]->frequency - freq) > fabs(station_list[i]->frequency - freq))) + station_list[0] = station_list[i]; + nb_stations = station_list[0]->modulation == modulation; + } - station = av_mallocz(sizeof(*station)); - if (!station) - return AVERROR(ENOMEM); + if (!nb_stations) { + station = av_mallocz(sizeof(*station)); + if (!station) + return AVERROR(ENOMEM); + station->frequency = freq; + } else { + station = station_list[0]; + // We will update the frequency so we need to reinsert + tree_remove(&sdr->station_root, station, station_cmp, &next); + station->frequency = station->nb_frequency * station->frequency + freq; + station->timeout = 0; + } + station->frequency /= ++station->nb_frequency; station->modulation = modulation; - station->frequency = freq; station->bandwidth = bandwidth; station->bandwidth_p2 = bandwidth_p2; station->score = score; tmp = tree_insert(&sdr->station_root, station, station_cmp, &next); if (tmp && tmp != station) { - //unlikely + //This will not happen in real C implementations but floats allow odd things in theory av_freep(&station); } av_freep(&next); @@ -2025,6 +2053,9 @@ int avpriv_sdr_read_close(AVFormatContext *s) } sdr->nb_stations = 0; av_freep(&sdr->station); + av_tree_enumerate(sdr->station_root, NULL, NULL, free_station_enu); + av_tree_destroy(sdr->station_root); + sdr->station_root = NULL; av_freep(&sdr->windowed_block); av_freep(&sdr->block);