From patchwork Fri Jul 7 17:22:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 42521 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:3b1e:b0:12b:9ae3:586d with SMTP id c30csp7449847pzh; Fri, 7 Jul 2023 10:22:58 -0700 (PDT) X-Google-Smtp-Source: APBJJlEBV2j/qKetBJtZUF2a4EiephFzVft9a3ulBoKmFl8OxbGQUinCpsXDyAB8Vhxo21FTfD4m X-Received: by 2002:a50:ed92:0:b0:51e:2492:3202 with SMTP id h18-20020a50ed92000000b0051e24923202mr4702519edr.33.1688750577786; Fri, 07 Jul 2023 10:22:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688750577; cv=none; d=google.com; s=arc-20160816; b=NB15VzliptGa3MXwwEM0rJvPSUH6Oj3tN1D0WQDvL0v4DDr/w1brKltzqHlYXG7Vs/ 2l/fttY67uoZSwUHG5YqX36PDhMxvSYCZWnWEnBghvDr+5bKhwvvCm+6aCgYp8r9cTX3 htlcYRZUh9DoLVT5U051ZCZf8V6KowEjqdoq2UR7S0Cof2o+RR/8GxcAz6UJDEahYSdM TeP5g/Q1PYXDHafl3OkjPsCj29iycJ2zi6yD0Mj9+LLU7aWsvFOQiwa6vI52ARWcQxKQ AoG1MgNiqggnr92F0BsXsf73stfeqodhvWbD6akQlUD5JjK5CsdJUn/r22ePmgz+KG4I yeng== 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=VZryDU/kTKGSbswf55ybtUoTIzac3P7+SatIP6qvNeo=; fh=YYwLYmpaV0Fpw/rxmSKNRLS2XzDkAlGbHATiKOPtZrY=; b=Hvjgpn/GlScDitobuCGTN4+OpL7OTJzR2cpkqDjes5VoP2LiZQMLPQvObNwxqn8L0c 2/IpAYktgPA1j735J5Cdqkh6L3R46uTgyTcO8/GKWhX6q+Oc4X+HGIrLFn4xg1T1lNG9 Qi6kpK2KFLxm0yK2ge9Wl1Nfs5G3ZBAQnRt/uCBJkbhOlqHfzIss5PgOd47cFAQ4+Zq+ SAdp5ru3RTqVVuVRv2C83jHtC/JuHznCqtlvuCybEzJRhohuDVEJeRL1r3RVeqic5BA0 EZwZWi6u37JTbZ6OQk9PESOVQoXBVPzCpeCYbpgYJRtXkDw+9ktS04iIgcZuajutlmgF YeLg== 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 w1-20020aa7d281000000b0051dd43ad4b1si2744288edq.1.2023.07.07.10.22.57; Fri, 07 Jul 2023 10:22:57 -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 09FB768C7C7; Fri, 7 Jul 2023 20:22:37 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net [217.70.183.201]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 34C4A68C77F for ; Fri, 7 Jul 2023 20:22:30 +0300 (EEST) X-GND-Sasl: michael@niedermayer.cc Received: by mail.gandi.net (Postfix) with ESMTPSA id 6A5BF1BF205 for ; Fri, 7 Jul 2023 17:22:29 +0000 (UTC) From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Fri, 7 Jul 2023 19:22:18 +0200 Message-Id: <20230707172224.2368067-3-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 3/9] avradio/sdr: consolidate the candidate station list with the main list 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: f+A5mq1cFlpI This way any updates to one is reflected in the other --- libavradio/sdr.h | 1 + libavradio/sdrdemux.c | 53 ++++++++++++++++++++++--------------------- 2 files changed, 28 insertions(+), 26 deletions(-) diff --git a/libavradio/sdr.h b/libavradio/sdr.h index 29465df0a1..4b1543efd3 100644 --- a/libavradio/sdr.h +++ b/libavradio/sdr.h @@ -74,6 +74,7 @@ typedef struct Station { int64_t bandwidth; int64_t bandwidth_p2; float score; + int in_station_list; ///< non zero if this station is in the station list int timeout; //since how many blocks was this detectable but not detected int multiplex_index; //DAB can have multiple stations on one frequency diff --git a/libavradio/sdrdemux.c b/libavradio/sdrdemux.c index 41eda615ae..7744ecdac0 100644 --- a/libavradio/sdrdemux.c +++ b/libavradio/sdrdemux.c @@ -180,7 +180,6 @@ static int create_station(SDRContext *sdr, Station *candidate_station) { int64_t bandwidth = candidate_station->bandwidth; int64_t bandwidth_p2 = candidate_station->bandwidth_p2; float score = candidate_station->score; - Station *station; void *tmp; int i; Station *best_station = NULL; @@ -191,6 +190,9 @@ static int create_station(SDRContext *sdr, Station *candidate_station) { int nb_candidate_conflict = 0; int nb_candidate_match = 0; + if (candidate_station->in_station_list) + return 0; + for (i=0; inb_stations; i++) { double delta = fabs(sdr->station[i]->frequency - freq); // Station already added, or we have 2 rather close stations @@ -215,10 +217,16 @@ static int create_station(SDRContext *sdr, Station *candidate_station) { best_station->score, score, best_station->frequency - freq, best_station->frequency, freq ); - best_station->frequency = freq; - best_station->score = score; + + if (best_station->stream) { + candidate_station->stream = best_station->stream; + best_station->stream = NULL; + candidate_station->stream->station = candidate_station; + } + candidate_station->in_station_list = 1; + best_station->in_station_list = 0; + sdr->station[best_station_index] = candidate_station; } - best_station->timeout = 0; return best_station_index; } Station *station_list[1000]; @@ -227,17 +235,21 @@ static int create_station(SDRContext *sdr, Station *candidate_station) { nb_candidate_match += candidate_station->nb_frequency - 1; for (i=0; ifrequency - freq); + Station *s = station_list[i]; + double delta = fabs(s->frequency - 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 += station_list[i]->nb_frequency; + if (modulation == s->modulation && delta < freq_precission && s != candidate_station) { + nb_candidate_match += s->nb_frequency; } - if (modulation != station_list[i]->modulation && delta < (bandwidth + station_list[i]->bandwidth)/2.1) - nb_candidate_conflict += station_list[i]->nb_frequency; + if (modulation != s->modulation && delta < (bandwidth + s->bandwidth)/2.1) + nb_candidate_conflict += s->nb_frequency; } //if we have a recent conflict with an established station, skip this one if (conflict < CANDIDATE_STATION_TIMEOUT) return -1; + if (conflict < candidate_station->timeout) + return -1; //AM detection is less reliable ATM so we dont want it to override FM stations if (modulation == AM && conflict < INT_MAX) @@ -255,7 +267,8 @@ static int create_station(SDRContext *sdr, Station *candidate_station) { // We recheck that the stations we remove are not active because floating point could round differently if (sdr->station[i]->stream == NULL && modulation != sdr->station[i]->modulation && delta < (bandwidth + sdr->station[i]->bandwidth)/2.1) { - free_station(sdr->station[i]); + + sdr->station[i]->in_station_list = 0; sdr->station[i--] = sdr->station[--sdr->nb_stations]; } } @@ -266,17 +279,8 @@ static int create_station(SDRContext *sdr, Station *candidate_station) { return AVERROR(ENOMEM); sdr->station = tmp; - station = av_mallocz(sizeof(*station)); - if (!station) - return AVERROR(ENOMEM); - - sdr->station[sdr->nb_stations++] = station; - - station->modulation = modulation; - station->frequency = freq; - station->bandwidth = bandwidth; - station->bandwidth_p2 = bandwidth_p2; - station->score = score; + sdr->station[sdr->nb_stations++] = candidate_station; + candidate_station->in_station_list = 1; av_log(sdr, AV_LOG_INFO, "create_station %d f:%f bw:%"PRId64"/%"PRId64" score: %f\n", modulation, freq, bandwidth, bandwidth_p2, score); @@ -340,7 +344,7 @@ static void decay_stations(SDRContext *sdr) continue; if (station->timeout++ > STATION_TIMEOUT) { - free_station(station); + station->in_station_list = 0; sdr->station[i--] = sdr->station[--sdr->nb_stations]; } } @@ -348,7 +352,7 @@ static void decay_stations(SDRContext *sdr) for (int i=0; itimeout++ > CANDIDATE_STATION_TIMEOUT) { + if (station->timeout++ > CANDIDATE_STATION_TIMEOUT && !station->in_station_list) { struct AVTreeNode *next = NULL; tree_remove(&sdr->station_root, station, station_cmp, &next); av_freep(&next); @@ -2048,9 +2052,6 @@ int avpriv_sdr_read_close(AVFormatContext *s) sst->frame_size = 0; } - for (i = 0; i < sdr->nb_stations; i++) { - free_station(sdr->station[i]); - } sdr->nb_stations = 0; av_freep(&sdr->station); av_tree_enumerate(sdr->station_root, NULL, NULL, free_station_enu);