From patchwork Tue Jul 11 21:19:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 42607 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:6da1:b0:131:a7d0:bc6d with SMTP id gl33csp1731532pzb; Tue, 11 Jul 2023 14:21:00 -0700 (PDT) X-Google-Smtp-Source: APBJJlH3rLEMuwaPyQXmOq+rui8+6qKO+n0hJ0VcbBlw7rGkqJuMv72nwFk2J38jmQpejGBdJOjC X-Received: by 2002:adf:e7c1:0:b0:313:f68c:cfe9 with SMTP id e1-20020adfe7c1000000b00313f68ccfe9mr11106350wrn.35.1689110460500; Tue, 11 Jul 2023 14:21:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689110460; cv=none; d=google.com; s=arc-20160816; b=aLflHB81T7/rglLiPtYn132CfMoOdJit2546zQOYrrFLZojlhfRHWLNr8arRKmQJIg fDw/QC0XLLD9QF4k6s1gLepe+gMxj6ONzX0e6p2cDqDLfArnMro0Lol/uyfB05vzNIBY 4jdodRhvfe7beFplZQ+mOZ7Sv5M3QPiLUuvGSJvwY6WVill1r2aXlrkCEngkpJj6MCR5 KzGK7xA1UYsWsksiTbFDM4N3/R8EPOro3RWTmidn2seqmYCeHy3/jJouP2eaYj9+mk3v EAWzHmtyGWWHiM2JHLdOVuNjyCbNyrucerHEHqSeYPI4K5Y8UjZMkqFlYE6MRmED98Yk 8d/Q== 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=6TbJkhuLMa0aLFE6aYhRbn4SBwcFfikreczbh9lK2Jk=; fh=YYwLYmpaV0Fpw/rxmSKNRLS2XzDkAlGbHATiKOPtZrY=; b=ZtwlVEPGuO2rHVsVHq2USETbSnU2zaCbRUiEcX6Om5T85Ak6+V/nM6toyUS7uHYkOT /cPhQEzV++R69gyQbpcS8tvyJIfjMEfCyH1aX6iv0GBXL+A+xEOq9dyb/zP3dnP95b82 tE4a3Qqa9drGGVh0v8Pq7VHuv+umS6NVO/D9lXnKxYVoPbH6C0AVtdMvTnZshPuyCkXL wc6mVqJ3UzlL9g553sTtlgp6tt8pmnPHrVTLpAOxV1HAUQnf4vPilFsSQZHX8YKgDEpu iVC0BhFRaikMi13oS/jSGEfAOEO11pWKBJ9GbgxJyBPGGjWsQsCU1Tsi+vMKhNpDlq19 u7nw== 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 f1-20020a50ee81000000b0051dd585e8dcsi3166352edr.479.2023.07.11.14.21.00; Tue, 11 Jul 2023 14:21:00 -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 B960868C654; Wed, 12 Jul 2023 00:19:31 +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 A9CB468BF69 for ; Wed, 12 Jul 2023 00:19:23 +0300 (EEST) Received: by mail.gandi.net (Postfix) with ESMTPSA id E29991C0003 for ; Tue, 11 Jul 2023 21:19:22 +0000 (UTC) From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Tue, 11 Jul 2023 23:19:08 +0200 Message-Id: <20230711211910.1257355-10-michael@niedermayer.cc> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230711211910.1257355-1-michael@niedermayer.cc> References: <20230711211910.1257355-1-michael@niedermayer.cc> MIME-Version: 1.0 X-GND-Sasl: michael@niedermayer.cc Subject: [FFmpeg-devel] [PATCH 10/12] avradio/sdr: Move tx contexts out of stream so its not duplicated 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: 9BnnHIncIwlz Signed-off-by: Michael Niedermayer --- libavradio/sdr.h | 10 +++++---- libavradio/sdrdemux.c | 48 +++++++++++++++++++++++-------------------- 2 files changed, 32 insertions(+), 26 deletions(-) diff --git a/libavradio/sdr.h b/libavradio/sdr.h index 8d7ab803d4..cb4b6dc68b 100644 --- a/libavradio/sdr.h +++ b/libavradio/sdr.h @@ -99,10 +99,6 @@ typedef struct FIFOElement { } FIFOElement; typedef struct SDRStream { - AVTXContext *fft_ctx; - AVTXContext *ifft_p2_ctx; - av_tx_fn fft; - av_tx_fn ifft_p2; int processing_index; float *out_buf; @@ -172,9 +168,15 @@ typedef struct SDRContext { float *fm_window_p2; AVTXContext *am_ifft_ctx; + AVTXContext *am_fft_ctx; AVTXContext *fm_ifft_ctx; + AVTXContext *fm_fft_ctx; + AVTXContext *fm_ifft_p2_ctx; av_tx_fn am_ifft; + av_tx_fn am_fft; av_tx_fn fm_ifft; + av_tx_fn fm_fft; + av_tx_fn fm_ifft_p2; int am_mode; ///< AMMode but using int for generic option access int emphasis_mode; diff --git a/libavradio/sdrdemux.c b/libavradio/sdrdemux.c index 6442d251f6..5d58d81843 100644 --- a/libavradio/sdrdemux.c +++ b/libavradio/sdrdemux.c @@ -991,7 +991,7 @@ static int demodulate_fm(SDRContext *sdr, int stream_index, AVPacket *pkt) //FIXME this only needs to be a RDFT //CONSIDER, this and in fact alot can be done with bandpass and lowpass filters instead of FFTs, find out which is better //CONSIDER synthesizing the carrier instead of IFFT, we have all parameters for that - sst->fft(sst->fft_ctx, sdr->fm_block, sdr->fm_iblock, sizeof(AVComplexFloat)); + sdr->fm_fft(sdr->fm_fft_ctx, sdr->fm_block, sdr->fm_iblock, sizeof(AVComplexFloat)); // Only the low N/2+1 are used the upper is just a reflection carrier19_i_exact = find_am_carrier(sdr, sdr->fm_block, 2*sdr->fm_block_size, (void*)(sdr->fm_block + 1 + sdr->fm_block_size), carrier19_i, 10, 10); @@ -1002,11 +1002,11 @@ static int demodulate_fm(SDRContext *sdr, int stream_index, AVPacket *pkt) memset(sdr->fm_block + i, 0, 2*sdr->fm_block_size_p2 * sizeof(AVComplexFloat)); memcpy(sdr->fm_block + i, sdr->fm_block + carrier19_i, sizeof(AVComplexFloat)*(W+1)); memcpy(sdr->fm_block + i + 2*sdr->fm_block_size_p2 - W, sdr->fm_block + carrier19_i - W, sizeof(AVComplexFloat)*W); - sst->ifft_p2(sst->ifft_p2_ctx, sdr->fm_icarrier, sdr->fm_block + i, sizeof(AVComplexFloat)); + sdr->fm_ifft_p2(sdr->fm_ifft_p2_ctx, sdr->fm_icarrier, sdr->fm_block + i, sizeof(AVComplexFloat)); memcpy(sdr->fm_block + i, sdr->fm_block + 3*carrier19_i, sizeof(AVComplexFloat)*len2_4_i); 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); - sst->ifft_p2(sst->ifft_p2_ctx, sdr->fm_iside , sdr->fm_block + i, sizeof(AVComplexFloat)); + 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); @@ -1014,12 +1014,12 @@ static int demodulate_fm(SDRContext *sdr, int stream_index, AVPacket *pkt) 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); - sst->ifft_p2(sst->ifft_p2_ctx, sdr->fm_iside , sdr->fm_block + i, sizeof(AVComplexFloat)); + 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); } 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); - sst->ifft_p2(sst->ifft_p2_ctx, sdr->fm_iblock , sdr->fm_block, sizeof(AVComplexFloat)); + 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)); scale = 5 / (M_PI * 2*sdr->fm_block_size); @@ -1096,11 +1096,6 @@ static void free_stream(SDRContext *sdr, int stream_index) AVStream *st = s->streams[stream_index]; SDRStream *sst = st->priv_data; - av_tx_uninit(&sst->fft_ctx); - av_tx_uninit(&sst->ifft_p2_ctx); - sst->fft = NULL; - sst->ifft_p2 = NULL; - av_freep(&sst->out_buf); } @@ -1138,15 +1133,6 @@ static int setup_stream(SDRContext *sdr, int stream_index, Station *station) int block_size; if (sst->station->modulation == FM) { - //Allocate 2nd stage demodulation fields if needed - ret = av_tx_init(&sst-> fft_ctx, &sst-> fft, AV_TX_FLOAT_FFT, 0, 2*sdr->fm_block_size , NULL, 0); - if (ret < 0) - return ret; - - ret = av_tx_init(&sst->ifft_p2_ctx, &sst->ifft_p2, AV_TX_FLOAT_FFT, 1, 2*sdr->fm_block_size_p2, NULL, 0); - if (ret < 0) - return ret; - block_size = sdr->fm_block_size; } else block_size = sdr->am_block_size; @@ -1523,10 +1509,22 @@ int ff_sdr_common_init(AVFormatContext *s) if (ret < 0) return ret; + ret = av_tx_init(&sdr->am_fft_ctx, &sdr->am_fft, AV_TX_FLOAT_FFT, 0, 2*sdr->am_block_size , NULL, 0); + if (ret < 0) + return ret; + ret = av_tx_init(&sdr->fm_ifft_ctx, &sdr->fm_ifft, AV_TX_FLOAT_FFT, 1, 2*sdr->fm_block_size, NULL, 0); if (ret < 0) return ret; + ret = av_tx_init(&sdr->fm_fft_ctx, &sdr->fm_fft, AV_TX_FLOAT_FFT, 0, 2*sdr->fm_block_size , NULL, 0); + if (ret < 0) + return ret; + + ret = av_tx_init(&sdr->fm_ifft_p2_ctx, &sdr->fm_ifft_p2, AV_TX_FLOAT_FFT, 1, 2*sdr->fm_block_size_p2, NULL, 0); + if (ret < 0) + return ret; + init_window(sdr, sdr->window, sdr->block_size); for (int i = 0; i < 2 * sdr->block_size; i++) @@ -1998,10 +1996,16 @@ int ff_sdr_read_close(AVFormatContext *s) av_tx_uninit(&sdr->fft_ctx); av_tx_uninit(&sdr->am_ifft_ctx); + av_tx_uninit(&sdr->am_fft_ctx); av_tx_uninit(&sdr->fm_ifft_ctx); - sdr->fft = NULL; - sdr->am_ifft = NULL; - sdr->fm_ifft = NULL; + av_tx_uninit(&sdr->fm_fft_ctx); + av_tx_uninit(&sdr->fm_ifft_p2_ctx); + sdr->fft = NULL; + sdr->am_ifft = NULL; + sdr->am_fft = NULL; + sdr->fm_ifft = NULL; + sdr->fm_fft = NULL; + sdr->fm_ifft_p2 = NULL; avio_close(sdr->dump_avio);