[FFmpeg-devel] [PATCH 5/5] avradio/sdrdemux: store min/max frequency, driver, label and tuner
Michael Niedermayer
michael at niedermayer.cc
Sat Jul 22 17:11:04 EEST 2023
Signed-off-by: Michael Niedermayer <michael at niedermayer.cc>
---
libavradio/sdr.h | 1 +
libavradio/sdrdemux.c | 35 ++++++++++++++++++++++++++++++++++-
libavradio/sdrinradio.c | 14 ++++++++++++++
3 files changed, 49 insertions(+), 1 deletion(-)
diff --git a/libavradio/sdr.h b/libavradio/sdr.h
index 4349763bd1..de0a479d26 100644
--- a/libavradio/sdr.h
+++ b/libavradio/sdr.h
@@ -138,6 +138,7 @@ typedef struct SDRContext {
Mode mode;
AVRational fps;
char *driver_name;
+ AVDictionary *driver_dict;
char *dump_url;
int fileheader_size;
AVIOContext *dump_avio;
diff --git a/libavradio/sdrdemux.c b/libavradio/sdrdemux.c
index 09d720de23..bb33c69668 100644
--- a/libavradio/sdrdemux.c
+++ b/libavradio/sdrdemux.c
@@ -1723,6 +1723,9 @@ static int sdrfile_initial_setup(AVFormatContext *s)
} else
return AVERROR_INVALIDDATA;
+ sdr->min_freq = 0;
+ sdr->max_freq = 40 * 1000*1000*1000LL;
+
avio_skip(s->pb, 3); //BE
sdr->sdr_sample_rate = avio_rb32(s->pb);
avio_rb32(s->pb); //block_size
@@ -1731,6 +1734,26 @@ static int sdrfile_initial_setup(AVFormatContext *s)
if (version > AV_RB24("000")) {
sdr->bandwidth = avio_rb32(s->pb);
sdr->fileheader_size = avio_rb32(s->pb);
+ if (sdr->fileheader_size < 48 || sdr->fileheader_size > 100000)
+ return AVERROR_INVALIDDATA;
+ if (version > AV_RB24("001")) {
+ char *tmp = av_malloc(sdr->fileheader_size);
+ if (!tmp)
+ return AVERROR(ENOMEM);
+
+ sdr->min_freq = avio_rb64(s->pb);
+ sdr->max_freq = avio_rb64(s->pb);
+ avio_get_str(s->pb, sdr->fileheader_size, tmp, sdr->fileheader_size);
+ sdr->driver_name = av_strdup(tmp);
+
+ avio_get_str(s->pb, sdr->fileheader_size, tmp, sdr->fileheader_size);
+ if (*tmp)
+ av_dict_set(&sdr->driver_dict, "label", tmp, 0);
+
+ avio_get_str(s->pb, sdr->fileheader_size, tmp, sdr->fileheader_size);
+ if (*tmp)
+ av_dict_set(&sdr->driver_dict, "tuner", tmp, 0);
+ }
} else {
sdr->bandwidth = sdr->sdr_sample_rate;
sdr->fileheader_size = 40;
@@ -1842,9 +1865,11 @@ process_next_block:
sdr->block_center_freq = fifo_element[0].center_frequency;
if (sdr->dump_avio) {
- uint8_t header[16] = "FFSDR001int16BE";
+ uint8_t header[16] = "FFSDR002int16BE";
uint8_t *tmp = (void*)sdr->windowed_block; //We use an unused array as temporary here
int64_t sizepos, endpos;
+ AVDictionaryEntry *e_label = av_dict_get(sdr->driver_dict, "label", NULL, 0);
+ AVDictionaryEntry *e_tuner = av_dict_get(sdr->driver_dict, "tuner", NULL, 0);
if (sdr->sample_size == 2)
memcpy(header + 11, "08", 2);
@@ -1858,6 +1883,12 @@ process_next_block:
sizepos = avio_tell(sdr->dump_avio);
avio_wb32(sdr->dump_avio, 0);
+ avio_wb64(sdr->dump_avio, sdr->min_freq);
+ avio_wb64(sdr->dump_avio, sdr->max_freq);
+ avio_put_str(sdr->dump_avio, sdr->driver_name);
+ avio_put_str(sdr->dump_avio, e_label ? e_label->value : NULL);
+ avio_put_str(sdr->dump_avio, e_tuner ? e_tuner->value : NULL);
+
endpos = avio_tell(sdr->dump_avio);
avio_seek(sdr->dump_avio, sizepos, SEEK_SET);
@@ -2202,6 +2233,8 @@ int ff_sdr_read_close(AVFormatContext *s)
avio_close(sdr->dump_avio);
+ av_dict_free(&sdr->driver_dict);
+
return 0;
}
diff --git a/libavradio/sdrinradio.c b/libavradio/sdrinradio.c
index d12b0b73fe..c24a30d746 100644
--- a/libavradio/sdrinradio.c
+++ b/libavradio/sdrinradio.c
@@ -161,6 +161,7 @@ static int sdrindev_initial_hw_setup(AVFormatContext *s)
SoapySDRDevice *soapy = NULL;
SoapySDRStream *soapyRxStream = NULL;
const char * soapy_format;
+ AVDictionaryEntry *e_label, *e_serial;
sdr->read_callback = sdrindev_read_callback;
sdr->set_frequency_callback = sdrindev_set_frequency_callback;
@@ -171,6 +172,7 @@ static int sdrindev_initial_hw_setup(AVFormatContext *s)
results = SoapySDRDevice_enumerate(NULL, &length);
for (i = 0; i < length; i++) {
int usable = 1;
+ int selected = 0;
for (int j = 0; j < results[i].size; j++) {
if (!strcmp("driver", results[i].keys[j])) {
if (!strcmp("audio", results[i].vals[j])) {
@@ -180,7 +182,11 @@ static int sdrindev_initial_hw_setup(AVFormatContext *s)
if (!sdr->driver_name)
return AVERROR(ENOMEM);
}
+ if(usable)
+ selected = !strcmp(sdr->driver_name, results[i].vals[j]);
}
+ if (selected)
+ av_dict_set(&sdr->driver_dict, results[i].keys[j], results[i].vals[j], 0);
}
if (!usable)
continue;
@@ -191,6 +197,14 @@ static int sdrindev_initial_hw_setup(AVFormatContext *s)
}
SoapySDRKwargsList_clear(results, length);
+ e_serial = av_dict_get(sdr->driver_dict, "serial", NULL, 0);
+ e_label = av_dict_get(sdr->driver_dict, "label", NULL, 0);
+ if (e_serial && e_label) {
+ char *p = strstr(e_label->value, e_serial->value);
+ if (p)
+ *p = 0; // we store this in dump url, preserve users privacy
+ }
+
av_log(s, AV_LOG_INFO, "Opening %s\n", sdr->driver_name);
if (!sdr->driver_name)
return AVERROR(EINVAL); //No driver specified and none found
--
2.31.1
More information about the ffmpeg-devel
mailing list