Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: Michael Niedermayer <michael@niedermayer.cc>
To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org>
Subject: [FFmpeg-devel] [PATCH 5/5] avradio/sdrdemux: store min/max frequency, driver, label and tuner
Date: Sat, 22 Jul 2023 16:11:04 +0200
Message-ID: <20230722141104.3327415-5-michael@niedermayer.cc> (raw)
In-Reply-To: <20230722141104.3327415-1-michael@niedermayer.cc>

Signed-off-by: Michael Niedermayer <michael@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

_______________________________________________
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".

  parent reply	other threads:[~2023-07-22 14:11 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-22 14:11 [FFmpeg-devel] [PATCH 1/5] avradio/vissualize: support simple skiping of chars Michael Niedermayer
2023-07-22 14:11 ` [FFmpeg-devel] [PATCH 2/5] avradio/vissualize: change color of the active station Michael Niedermayer
2023-07-22 14:11 ` [FFmpeg-devel] [PATCH 3/5] avradio/sdr: Remove direct inclusion of pthread.h Michael Niedermayer
2023-07-22 14:11 ` [FFmpeg-devel] [PATCH 4/5] avradio/sdrdemux: avoid literal offsets in dump code Michael Niedermayer
2023-07-22 14:11 ` Michael Niedermayer [this message]
2023-07-24 17:07 ` [FFmpeg-devel] [PATCH 1/5] avradio/vissualize: support simple skiping of chars 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=20230722141104.3327415-5-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