[FFmpeg-devel] [PATCH 7/7] avradio/sdr: workaround inverted gain parameter on sdrplay
Michael Niedermayer
michael at niedermayer.cc
Mon Jul 17 03:27:04 EEST 2023
Signed-off-by: Michael Niedermayer <michael at niedermayer.cc>
---
libavradio/sdr.h | 1 +
libavradio/sdrdemux.c | 1 +
libavradio/sdrinradio.c | 7 +++++++
3 files changed, 9 insertions(+)
diff --git a/libavradio/sdr.h b/libavradio/sdr.h
index 395b056531..27ec1db4f3 100644
--- a/libavradio/sdr.h
+++ b/libavradio/sdr.h
@@ -257,6 +257,7 @@ typedef struct SDRContext {
int missing_streams;
int rtlsdr_fixes;
+ int sdrplay_fixes;
} SDRContext;
typedef struct ModulationDescriptor {
diff --git a/libavradio/sdrdemux.c b/libavradio/sdrdemux.c
index 5214aea7be..1b3061a406 100644
--- a/libavradio/sdrdemux.c
+++ b/libavradio/sdrdemux.c
@@ -2180,6 +2180,7 @@ const AVOption ff_sdr_options[] = {
{ "driver" , "sdr driver name" , OFFSET(driver_name), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC},
{ "rtlsdr_fixes" , "workaround rtlsdr issues", OFFSET(rtlsdr_fixes), AV_OPT_TYPE_INT , {.i64 = -1}, -1, 1, DEC},
+ { "sdrplay_fixes" , "workaround sdrplay issues", OFFSET(sdrplay_fixes), AV_OPT_TYPE_INT , {.i64 = -1}, -1, 1, DEC},
{ "sdr_sr" , "sdr sample rate" , OFFSET(sdr_sample_rate ), AV_OPT_TYPE_INT , {.i64 = 0}, 0, INT_MAX, DEC},
{ "sdr_freq", "sdr frequency" , OFFSET(wanted_freq), AV_OPT_TYPE_INT64 , {.i64 = 9000000}, 0, INT64_MAX, DEC},
{ "gain" , "sdr overall gain", OFFSET(sdr_gain), AV_OPT_TYPE_INT , {.i64 = GAIN_SDR_AGC}, -3, INT_MAX, DEC, "gain"},
diff --git a/libavradio/sdrinradio.c b/libavradio/sdrinradio.c
index 63a9cade78..f824a1d190 100644
--- a/libavradio/sdrinradio.c
+++ b/libavradio/sdrinradio.c
@@ -76,6 +76,11 @@ static int sdrindev_set_gain_callback(SDRContext *sdr, float gain)
if (sdr->sdr_gain == GAIN_DEFAULT)
return 0;
+ //sdrplay has a inverted gain range, not using max_gain as this is a user parameter
+ if (sdr->sdrplay_fixes > 0) {
+ gain = FFMIN(48 - gain, 45);
+ }
+
if (soapy) {
int ret = SoapySDRDevice_setGainMode(soapy, SOAPY_SDR_RX, 0, sdr->sdr_gain == GAIN_SDR_AGC);
if (ret) {
@@ -192,6 +197,8 @@ static int sdrindev_initial_hw_setup(AVFormatContext *s)
if (sdr->rtlsdr_fixes < 0)
sdr->rtlsdr_fixes = !strcmp(sdr->driver_name, "rtlsdr");
+ if (sdr->sdrplay_fixes < 0)
+ sdr->sdrplay_fixes = !strcmp(sdr->driver_name, "sdrplay");
SoapySDRKwargs_set(&args, "driver", sdr->driver_name);
sdr->soapy = soapy = SoapySDRDevice_make(&args);
--
2.31.1
More information about the ffmpeg-devel
mailing list