From: Michael Niedermayer <michael@niedermayer.cc> To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org> Subject: [FFmpeg-devel] [PATCH 3/9] avradio/sdr: consolidate the candidate station list with the main list Date: Fri, 7 Jul 2023 19:22:18 +0200 Message-ID: <20230707172224.2368067-3-michael@niedermayer.cc> (raw) In-Reply-To: <20230707172224.2368067-1-michael@niedermayer.cc> 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; i<sdr->nb_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; i<nb_stations; i++) { int freq_precission = modulation == AM ? 5 : 50; - double delta = fabs(station_list[i]->frequency - 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; i<nb_stations; i++) { Station *station = station_list[i]; - if (station->timeout++ > 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".
next prev parent reply other threads:[~2023-07-07 17:22 UTC|newest] Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-07-07 17:22 [FFmpeg-devel] [PATCH 1/9] avradio/sdr: use AVTree for candidate stations Michael Niedermayer 2023-07-07 17:22 ` [FFmpeg-devel] [PATCH 2/9] avradio/sdr: Consolidate candidate station entries Michael Niedermayer 2023-07-07 17:22 ` Michael Niedermayer [this message] 2023-07-07 17:22 ` [FFmpeg-devel] [PATCH 4/9] avradio/sdr: Eliminate station list Michael Niedermayer 2023-07-07 17:22 ` [FFmpeg-devel] [PATCH 5/9] avradio/sdr: Allow user to adjust FM/AM thresholds Michael Niedermayer 2023-07-07 17:22 ` [FFmpeg-devel] [PATCH 6/9] avradio/sdrdemux: count timeout irrespective of a station being active Michael Niedermayer 2023-07-07 17:22 ` [FFmpeg-devel] [PATCH 7/9] avradio/sdr: Compute and use detection histogram Michael Niedermayer 2023-07-07 17:22 ` [FFmpeg-devel] [PATCH 8/9] avradio/sdrdemux: increase the FM station frequency tolerance Michael Niedermayer 2023-07-07 17:22 ` [FFmpeg-devel] [PATCH 9/9] avradio/sdrdemux: Use 2 differnt FM station detectors Michael Niedermayer 2023-07-08 15:42 ` [FFmpeg-devel] [PATCH 1/9] avradio/sdr: use AVTree for candidate stations Michael Niedermayer
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20230707172224.2368067-3-michael@niedermayer.cc \ --to=michael@niedermayer.cc \ --cc=ffmpeg-devel@ffmpeg.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git