From: Michael Niedermayer <michael@niedermayer.cc> To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org> Subject: [FFmpeg-devel] [PATCH 12/12] avradio/sdr: Process RDS of all stations not just the current one Date: Tue, 11 Jul 2023 23:19:10 +0200 Message-ID: <20230711211910.1257355-12-michael@niedermayer.cc> (raw) In-Reply-To: <20230711211910.1257355-1-michael@niedermayer.cc> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc> --- libavradio/sdr.h | 3 +- libavradio/sdrdemux.c | 69 +++++++++++++++++++++++++++++-------------- 2 files changed, 49 insertions(+), 23 deletions(-) diff --git a/libavradio/sdr.h b/libavradio/sdr.h index 3297584eae..6c4647823e 100644 --- a/libavradio/sdr.h +++ b/libavradio/sdr.h @@ -91,6 +91,7 @@ typedef struct Station { int rds_ring_pos; struct SDRStream *stream; + int processing_index; } Station; typedef struct FIFOElement { @@ -241,7 +242,7 @@ typedef struct ModulationDescriptor { /** * Demodulate given station into packet */ - int (*demodulate)(SDRContext *sdr, AVStream *st, AVPacket *pkt); + int (*demodulate)(SDRContext *sdr, Station *station, AVStream *st, AVPacket *pkt); } ModulationDescriptor; typedef struct BandDescriptor { diff --git a/libavradio/sdrdemux.c b/libavradio/sdrdemux.c index 19dd0ef381..e93cf4dd98 100644 --- a/libavradio/sdrdemux.c +++ b/libavradio/sdrdemux.c @@ -665,11 +665,11 @@ static av_always_inline void synchronous_am_demodulationN(AVComplexFloat *iblock } } -static int demodulate_am(SDRContext *sdr, AVStream *st, AVPacket *pkt) +static int demodulate_am(SDRContext *sdr, Station *station, AVStream *st, AVPacket *pkt) { SDRStream *sst = st->priv_data; - double freq = sst->station->frequency; - int64_t bandwidth = sst->station->bandwidth; + double freq = station->frequency; + int64_t bandwidth = station->bandwidth; int index = lrint(F2INDEX(freq)); int len = (bandwidth * 2ll * sdr->block_size + sdr->sdr_sample_rate/2) / sdr->sdr_sample_rate; float *newbuf; @@ -933,10 +933,9 @@ static int probe_fm(SDRContext *sdr) return 0; } -static int demodulate_fm(SDRContext *sdr, AVStream *st, AVPacket *pkt) +static int demodulate_fm(SDRContext *sdr, Station *station, AVStream *st, AVPacket *pkt) { - SDRStream *sst = st->priv_data; - Station *station = sst->station; + SDRStream *sst = st ? st->priv_data : NULL; double freq = station->frequency; int64_t bandwidth = station->bandwidth; @@ -954,6 +953,8 @@ static int demodulate_fm(SDRContext *sdr, AVStream *st, AVPacket *pkt) double carrier19_i_exact; int W= 5; + av_assert0(!st || (sst == station->stream && sst->station == station)); + //If only some of the bandwidth is available, just try with less int len2 = FFMIN(index, 2*sdr->block_size - index); if (len2 < len && len2 > len/2) @@ -962,11 +963,7 @@ static int demodulate_fm(SDRContext *sdr, AVStream *st, AVPacket *pkt) if (index + len >= 2*sdr->block_size || index - len < 0 || 2*len + 1 > 2*sdr->fm_block_size) - return AVERROR(ERANGE); - - newbuf = av_malloc(sizeof(*sst->out_buf) * 2 * sdr->fm_block_size); - if (!newbuf) - return AVERROR(ENOMEM); + return AVERROR(ERANGE); i = 2*len+1; memcpy(sdr->fm_block, sdr->block + index, sizeof(*sdr->fm_block) * (len + 1)); @@ -1006,20 +1003,29 @@ static int demodulate_fm(SDRContext *sdr, AVStream *st, AVPacket *pkt) memcpy(sdr->fm_block + i + 2*sdr->fm_block_size_p2 - len2_4_i, sdr->fm_block + 3*carrier19_i - len2_4_i, sizeof(AVComplexFloat)*len2_4_i); sdr->fm_ifft_p2(sdr->fm_ifft_p2_ctx, sdr->fm_iside , sdr->fm_block + i, sizeof(AVComplexFloat)); synchronous_am_demodulationN(sdr->fm_iside, sdr->fm_icarrier, sdr->fm_window_p2, 2*sdr->fm_block_size_p2, 3); - ff_sdr_decode_rds(sdr, sst->station, sdr->fm_iside); - - memcpy(sdr->fm_block + i, sdr->fm_block + 2*carrier19_i, sizeof(AVComplexFloat)*len17_i); - memcpy(sdr->fm_block + i + 2*sdr->fm_block_size_p2 - len17_i, sdr->fm_block + 2*carrier19_i - len17_i, sizeof(AVComplexFloat)*len17_i); - apply_deemphasis(sdr, sdr->fm_block + i, sdr->fm_block_size_p2, sample_rate_p2, + 1); - apply_deemphasis(sdr, sdr->fm_block + i + 2*sdr->fm_block_size_p2, sdr->fm_block_size_p2, sample_rate_p2, - 1); - sdr->fm_ifft_p2(sdr->fm_ifft_p2_ctx, sdr->fm_iside , sdr->fm_block + i, sizeof(AVComplexFloat)); - synchronous_am_demodulationN(sdr->fm_iside, sdr->fm_icarrier, sdr->fm_window_p2, 2*sdr->fm_block_size_p2, 2); + ff_sdr_decode_rds(sdr, station, sdr->fm_iside); + + if (st) { + memcpy(sdr->fm_block + i, sdr->fm_block + 2*carrier19_i, sizeof(AVComplexFloat)*len17_i); + memcpy(sdr->fm_block + i + 2*sdr->fm_block_size_p2 - len17_i, sdr->fm_block + 2*carrier19_i - len17_i, sizeof(AVComplexFloat)*len17_i); + apply_deemphasis(sdr, sdr->fm_block + i, sdr->fm_block_size_p2, sample_rate_p2, + 1); + apply_deemphasis(sdr, sdr->fm_block + i + 2*sdr->fm_block_size_p2, sdr->fm_block_size_p2, sample_rate_p2, - 1); + sdr->fm_ifft_p2(sdr->fm_ifft_p2_ctx, sdr->fm_iside , sdr->fm_block + i, sizeof(AVComplexFloat)); + synchronous_am_demodulationN(sdr->fm_iside, sdr->fm_icarrier, sdr->fm_window_p2, 2*sdr->fm_block_size_p2, 2); + } } + if (!st) + return 0; + memset(sdr->fm_block + len17_i, 0, (2*sdr->fm_block_size_p2 - len17_i) * sizeof(AVComplexFloat)); apply_deemphasis(sdr, sdr->fm_block, 2*sdr->fm_block_size_p2, sample_rate_p2, + 1); sdr->fm_ifft_p2(sdr->fm_ifft_p2_ctx, sdr->fm_iblock , sdr->fm_block, sizeof(AVComplexFloat)); memset(sdr->fm_iblock + 2*sdr->fm_block_size_p2, 0 ,(2*sdr->fm_block_size -2*sdr->fm_block_size_p2) * sizeof(AVComplexFloat)); + newbuf = av_malloc(sizeof(*sst->out_buf) * 2 * sdr->fm_block_size); + if (!newbuf) + return AVERROR(ENOMEM); + scale = 5 / (M_PI * 2*sdr->fm_block_size); for(i = 0; i<sdr->fm_block_size_p2; i++) { float m, q; @@ -1651,7 +1657,7 @@ process_next_block: } else if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { if (sst->station) { skip = 0; - ret = ff_sdr_modulation_descs[ sst->station->modulation ].demodulate(sdr, st, pkt); + ret = ff_sdr_modulation_descs[ sst->station->modulation ].demodulate(sdr, sst->station, st, pkt); if (ret < 0) { av_log(s, AV_LOG_ERROR, "demodulation failed ret = %d\n", ret); } @@ -1659,6 +1665,8 @@ process_next_block: } else av_assert0(0); sst->processing_index = 0; + if (sst->station) + sst->station->processing_index = 0; if (pkt && !skip) { pkt->stream_index = stream_index; pkt->dts = (sdr->pts & (-1<<FREQ_BITS)); @@ -1671,6 +1679,18 @@ process_next_block: } } + if (sdr->width > 1) { + Station *station_list[1000]; + int nb_stations = ff_sdr_find_stations(sdr, sdr->block_center_freq, sdr->sdr_sample_rate*0.5, station_list, FF_ARRAY_ELEMS(station_list)); + for (int i= 0; i<nb_stations; i++) { + Station *station = station_list[i]; + if (station->stream || station->modulation != FM || !station->processing_index || !station->in_station_list) + continue; + ff_sdr_modulation_descs[ FM ].demodulate(sdr, station, NULL, NULL); + station->processing_index = 0; + } + } + pthread_mutex_lock(&sdr->mutex); full_blocks = av_fifo_can_read(sdr->full_block_fifo) - 1; ret = av_fifo_peek(sdr->full_block_fifo, &fifo_element, 2, 0); @@ -1820,6 +1840,8 @@ process_next_block: // windowed_block is unused now, we can fill it with the next blocks data if (sdr->block_center_freq) { + Station *station_list[1000]; + int nb_stations; if (sdr->skip_probe-- <= 0) { //Probing takes a bit of time, lets not do it every time sdr->skip_probe = 5; @@ -1835,6 +1857,7 @@ process_next_block: create_stations(sdr); } + nb_stations = ff_sdr_find_stations(sdr, sdr->block_center_freq, sdr->sdr_sample_rate*0.5, station_list, FF_ARRAY_ELEMS(station_list)); if (sdr->mode == SingleStationMode) { AVStream *st = s->streams[sdr->single_ch_audio_st_index]; SDRStream *sst = st->priv_data; @@ -1845,8 +1868,6 @@ process_next_block: return ret; } } else { - Station *station_list[1000]; - int nb_stations = ff_sdr_find_stations(sdr, sdr->block_center_freq, sdr->sdr_sample_rate*0.5, station_list, FF_ARRAY_ELEMS(station_list)); av_assert0(sdr->mode == AllStationMode); for(int i = 0; i<nb_stations; i++) { Station *station = station_list[i]; @@ -1881,6 +1902,10 @@ process_next_block: SDRStream *sst = st->priv_data; sst->processing_index += sdr->block_size; } + for(int i = 0; i<nb_stations; i++) { + Station *station = station_list[i]; + station->processing_index += sdr->block_size; + } } sdr->last_pts = sdr->pts; -- 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-11 21:20 UTC|newest] Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-07-11 21:18 [FFmpeg-devel] [PATCH 01/12] avradio/sdrdemux: Fix use of uninitialized memory Michael Niedermayer 2023-07-11 21:19 ` [FFmpeg-devel] [PATCH 02/12] avradio/rds: Implement burst error decoder Michael Niedermayer 2023-07-11 21:19 ` [FFmpeg-devel] [PATCH 03/12] avradio/rds: Keep track of program_id Michael Niedermayer 2023-07-11 21:19 ` [FFmpeg-devel] [PATCH 04/12] avradio/sdr: Move rds_ring to Station Michael Niedermayer 2023-07-11 21:19 ` [FFmpeg-devel] [PATCH 05/12] avradio/rds: move phase 2 window to main context Michael Niedermayer 2023-07-11 21:19 ` [FFmpeg-devel] [PATCH 06/12] avradio/sdr: Warnings cleanup Michael Niedermayer 2023-07-11 21:19 ` [FFmpeg-devel] [PATCH 07/12] avradio/rds: warnings cleanup Michael Niedermayer 2023-07-11 21:19 ` [FFmpeg-devel] [PATCH 08/12] avradio/sdr: Move IFFT and block size to main context Michael Niedermayer 2023-07-11 21:19 ` [FFmpeg-devel] [PATCH 09/12] avradio/sdr: Move per stream arraies " Michael Niedermayer 2023-07-11 21:19 ` [FFmpeg-devel] [PATCH 10/12] avradio/sdr: Move tx contexts out of stream so its not duplicated Michael Niedermayer 2023-07-11 21:19 ` [FFmpeg-devel] [PATCH 11/12] avradio/sdr: Pass AVStream instead of int to demodulate Michael Niedermayer 2023-07-11 21:19 ` Michael Niedermayer [this message] 2023-07-12 23:26 ` [FFmpeg-devel] [PATCH 01/12] avradio/sdrdemux: Fix use of uninitialized memory 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=20230711211910.1257355-12-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