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 5F8F346CE0 for ; Fri, 7 Jul 2023 17:22:55 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C4E0768C7D2; Fri, 7 Jul 2023 20:22:36 +0300 (EEST) 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 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: 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); -- 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".