Re: NEW: comms/soapy-rtlsdr

Sebastian Reitenbach <[email protected]> Tue, 4 Aug 2026 14:46:29 +0200
Newsgroups gmane.os.openbsd.ports
Message-ID <CAEoLn68zELOZy5h=kGJ2beRD3xd5KdMEkYY3mArnnrOdin2-1A@mail.gmail.com>
--000000000000e27ce20658380b9a
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

lrz mr test that one as well!

On Fri, Jul 31, 2026 at 1:49=E2=80=AFPM SASANO Takayoshi <[email protected]=
> wrote:

> Hello,
>
> I tried CubicSDR with SoapyRTLSDR.
> It looks working but stucks when frequency is changed.
>
> Due to libusb's issue, rtlsdr_read_async() does not work well on OpenBSD.
> This affects rtl_tcp of comms/rtl-sdr and comms/soapy-rtlsdr,
> Airspy's SDR# (on Windows) with rtl_tcp (on OpenBSD) have same trouble.
>
> For testing, I rewrited rtl_tcp code with rtlsdr_read_sync().
> This is avaiable at https://github.com/jg1uaa/rtl_tcp_sync and
> I think this have enough performance.
>
> So, I did same thing for SoapyRTLSDR with rtlsdr_read_sync().
> If this works well, can I commit it?
> --
> SASANO Takayoshi (JG1UAA) <[email protected]>
>
> Index: Makefile
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
> RCS file: /cvs/ports/comms/soapy-rtlsdr/Makefile,v
> diff -u -p -r1.1.1.1 Makefile
> --- Makefile    29 May 2026 20:15:45 -0000      1.1.1.1
> +++ Makefile    31 Jul 2026 11:35:16 -0000
> @@ -1,6 +1,7 @@
>  COMMENT =3D              Soapy SDR plugin for RTL-SDR
>
>  V =3D                    0.3.3
> +REVISION =3D             0
>  GH_ACCOUNT =3D           pothosware
>  GH_PROJECT =3D           SoapyRTLSDR
>  GH_COMMIT =3D            b1f568d1b57cc973a1d2ee49be68d0d748d164e4
> Index: patches/patch-SoapyRTLSDR_hpp
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
> RCS file: patches/patch-SoapyRTLSDR_hpp
> diff -N patches/patch-SoapyRTLSDR_hpp
> --- /dev/null   1 Jan 1970 00:00:00 -0000
> +++ patches/patch-SoapyRTLSDR_hpp       31 Jul 2026 11:35:16 -0000
> @@ -0,0 +1,16 @@
> +--- SoapyRTLSDR.hpp.orig       Mon Aug 25 17:45:34 2025
> ++++ SoapyRTLSDR.hpp    Fri Jul 31 20:18:53 2026
> +@@ -264,9 +264,10 @@ class SoapyRTLSDR: public SoapySDR::Device (public)
> +         std::vector<signed char> data;
> +     };
> +
> +-    //async api usage
> +-    std::thread _rx_async_thread;
> +-    void rx_async_operation(void);
> ++    //sync api usage
> ++    std::atomic<bool> _rxRunning;
> ++    std::thread _rx_sync_thread;
> ++    void rx_sync_operation(void);
> +     void rx_callback(unsigned char *buf, uint32_t len);
> +
> +     std::mutex _buf_mutex;
> Index: patches/patch-Streaming_cpp
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
> RCS file: patches/patch-Streaming_cpp
> diff -N patches/patch-Streaming_cpp
> --- /dev/null   1 Jan 1970 00:00:00 -0000
> +++ patches/patch-Streaming_cpp 31 Jul 2026 11:35:16 -0000
> @@ -0,0 +1,75 @@
> +--- Streaming.cpp.orig Mon Aug 25 17:45:34 2025
> ++++ Streaming.cpp      Fri Jul 31 20:19:17 2026
> +@@ -80,6 +80,7 @@ SoapySDR::ArgInfoList SoapyRTLSDR::getStreamArgsInfo(c
> +
> +     streamArgs.push_back(buffersArg);
> +
> ++    // args for async no longer work, but kept for compatibility
> +     SoapySDR::ArgInfo asyncbuffsArg;
> +     asyncbuffsArg.key =3D "asyncBuffs";
> +     asyncbuffsArg.value =3D "0";
> +@@ -94,21 +95,23 @@ SoapySDR::ArgInfoList SoapyRTLSDR::getStreamArgsInfo=
(c
> + }
> +
> + /*******************************************************************
> +- * Async thread work
> ++ * Sync thread work
> +  ******************************************************************/
> +
> +-static void _rx_callback(unsigned char *buf, uint32_t len, void *ctx)
> ++void SoapyRTLSDR::rx_sync_operation(void)
> + {
> +-    //printf("_rx_callback\n");
> +-    SoapyRTLSDR *self =3D (SoapyRTLSDR *)ctx;
> +-    self->rx_callback(buf, len);
> +-}
> ++    int rxSize;
> ++    unsigned char *rxBuf =3D new unsigned char[bufferLength];
> +
> +-void SoapyRTLSDR::rx_async_operation(void)
> +-{
> +-    //printf("rx_async_operation\n");
> +-    rtlsdr_read_async(dev, &_rx_callback, this, asyncBuffs,
> bufferLength);
> +-    //printf("rx_async_operation done!\n");
> ++    //printf("rx_sync_operation\n");
> ++    while (_rxRunning) {
> ++        if (rtlsdr_read_sync(dev, (void *)rxBuf, bufferLength, &rxSize)
> < 0)
> ++            break;
> ++        rx_callback(rxBuf, rxSize);
> ++    }
> ++    //printf("rx_sync_operation done!\n");
> ++
> ++    delete[] rxBuf;
> + }
> +
> + void SoapyRTLSDR::rx_callback(unsigned char *buf, uint32_t len)
> +@@ -316,11 +319,12 @@ int SoapyRTLSDR::activateStream(
> +     resetBuffer =3D true;
> +     bufferedElems =3D 0;
> +
> +-    //start the async thread
> +-    if (not _rx_async_thread.joinable())
> ++    //start the sync thread
> ++    if (not _rx_sync_thread.joinable())
> +     {
> +         rtlsdr_reset_buffer(dev);
> +-        _rx_async_thread =3D std::thread(&SoapyRTLSDR::rx_async_operati=
on,
> this);
> ++        _rxRunning =3D true;
> ++        _rx_sync_thread =3D std::thread(&SoapyRTLSDR::rx_sync_operation=
,
> this);
> +     }
> +
> +     return 0;
> +@@ -329,10 +333,10 @@ int SoapyRTLSDR::activateStream(
> + int SoapyRTLSDR::deactivateStream(SoapySDR::Stream *stream, const int
> flags, const long long timeNs)
> + {
> +     if (flags !=3D 0) return SOAPY_SDR_NOT_SUPPORTED;
> +-    if (_rx_async_thread.joinable())
> ++    if (_rx_sync_thread.joinable())
> +     {
> +-        rtlsdr_cancel_async(dev);
> +-        _rx_async_thread.join();
> ++        _rxRunning =3D false;
> ++        _rx_sync_thread.join();
> +     }
> +     return 0;
> + }
>


--=20
https://buzzdeee.reitenba.ch

--000000000000e27ce20658380b9a
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">lrz mr test that one as well!</div><br><div class=3D"gmail=
_quote gmail_quote_container"><div dir=3D"ltr" class=3D"gmail_attr">On Fri,=
 Jul 31, 2026 at 1:49=E2=80=AFPM SASANO Takayoshi &lt;<a href=3D"mailto:uaa=
@mx5.nisiq.net">[email protected]</a>&gt; wrote:<br></div><blockquote class=
=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rg=
b(204,204,204);padding-left:1ex">Hello,<br>
<br>
I tried CubicSDR with SoapyRTLSDR.<br>
It looks working but stucks when frequency is changed.<br>
<br>
Due to libusb&#39;s issue, rtlsdr_read_async() does not work well on OpenBS=
D.<br>
This affects rtl_tcp of comms/rtl-sdr and comms/soapy-rtlsdr,<br>
Airspy&#39;s SDR# (on Windows) with rtl_tcp (on OpenBSD) have same trouble.=
<br>
<br>
For testing, I rewrited rtl_tcp code with rtlsdr_read_sync().<br>
This is avaiable at <a href=3D"https://github.com/jg1uaa/rtl_tcp_sync" rel=
=3D"noreferrer" target=3D"_blank">https://github.com/jg1uaa/rtl_tcp_sync</a=
> and<br>
I think this have enough performance.<br>
<br>
So, I did same thing for SoapyRTLSDR with rtlsdr_read_sync().<br>
If this works well, can I commit it?<br>
-- <br>
SASANO Takayoshi (JG1UAA) &lt;<a href=3D"mailto:[email protected]" target=
=3D"_blank">[email protected]</a>&gt;<br>
<br>
Index: Makefile<br>
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D<br>
RCS file: /cvs/ports/comms/soapy-rtlsdr/Makefile,v<br>
diff -u -p -r1.1.1.1 Makefile<br>
--- Makefile=C2=A0 =C2=A0 29 May 2026 20:15:45 -0000=C2=A0 =C2=A0 =C2=A0 1.=
1.1.1<br>
+++ Makefile=C2=A0 =C2=A0 31 Jul 2026 11:35:16 -0000<br>
@@ -1,6 +1,7 @@<br>
=C2=A0COMMENT =3D=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 Soapy SDR=
 plugin for RTL-SDR<br>
<br>
=C2=A0V =3D=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 0.3.3<br>
+REVISION =3D=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A00<br>
=C2=A0GH_ACCOUNT =3D=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0pothosware<br>
=C2=A0GH_PROJECT =3D=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0SoapyRTLSDR<br=
>
=C2=A0GH_COMMIT =3D=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 b1f568d1b57cc9=
73a1d2ee49be68d0d748d164e4<br>
Index: patches/patch-SoapyRTLSDR_hpp<br>
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D<br>
RCS file: patches/patch-SoapyRTLSDR_hpp<br>
diff -N patches/patch-SoapyRTLSDR_hpp<br>
--- /dev/null=C2=A0 =C2=A01 Jan 1970 00:00:00 -0000<br>
+++ patches/patch-SoapyRTLSDR_hpp=C2=A0 =C2=A0 =C2=A0 =C2=A031 Jul 2026 11:=
35:16 -0000<br>
@@ -0,0 +1,16 @@<br>
+--- SoapyRTLSDR.hpp.orig=C2=A0 =C2=A0 =C2=A0 =C2=A0Mon Aug 25 17:45:34 202=
5<br>
++++ SoapyRTLSDR.hpp=C2=A0 =C2=A0 Fri Jul 31 20:18:53 2026<br>
+@@ -264,9 +264,10 @@ class SoapyRTLSDR: public SoapySDR::Device (public)<b=
r>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0std::vector&lt;signed char&gt; data;<br>
+=C2=A0 =C2=A0 =C2=A0};<br>
+ <br>
+-=C2=A0 =C2=A0 //async api usage<br>
+-=C2=A0 =C2=A0 std::thread _rx_async_thread;<br>
+-=C2=A0 =C2=A0 void rx_async_operation(void);<br>
++=C2=A0 =C2=A0 //sync api usage<br>
++=C2=A0 =C2=A0 std::atomic&lt;bool&gt; _rxRunning;<br>
++=C2=A0 =C2=A0 std::thread _rx_sync_thread;<br>
++=C2=A0 =C2=A0 void rx_sync_operation(void);<br>
+=C2=A0 =C2=A0 =C2=A0void rx_callback(unsigned char *buf, uint32_t len);<br=
>
+ <br>
+=C2=A0 =C2=A0 =C2=A0std::mutex _buf_mutex;<br>
Index: patches/patch-Streaming_cpp<br>
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D<br>
RCS file: patches/patch-Streaming_cpp<br>
diff -N patches/patch-Streaming_cpp<br>
--- /dev/null=C2=A0 =C2=A01 Jan 1970 00:00:00 -0000<br>
+++ patches/patch-Streaming_cpp 31 Jul 2026 11:35:16 -0000<br>
@@ -0,0 +1,75 @@<br>
+--- Streaming.cpp.orig Mon Aug 25 17:45:34 2025<br>
++++ Streaming.cpp=C2=A0 =C2=A0 =C2=A0 Fri Jul 31 20:19:17 2026<br>
+@@ -80,6 +80,7 @@ SoapySDR::ArgInfoList SoapyRTLSDR::getStreamArgsInfo(c<b=
r>
+ <br>
+=C2=A0 =C2=A0 =C2=A0streamArgs.push_back(buffersArg);<br>
+ <br>
++=C2=A0 =C2=A0 // args for async no longer work, but kept for compatibilit=
y<br>
+=C2=A0 =C2=A0 =C2=A0SoapySDR::ArgInfo asyncbuffsArg;<br>
+=C2=A0 =C2=A0 =C2=A0asyncbuffsArg.key =3D &quot;asyncBuffs&quot;;<br>
+=C2=A0 =C2=A0 =C2=A0asyncbuffsArg.value =3D &quot;0&quot;;<br>
+@@ -94,21 +95,23 @@ SoapySDR::ArgInfoList SoapyRTLSDR::getStreamArgsInfo(c=
<br>
+ }<br>
+ <br>
+ /*******************************************************************<br>
+- * Async thread work<br>
++ * Sync thread work<br>
+=C2=A0 ******************************************************************/=
<br>
+ <br>
+-static void _rx_callback(unsigned char *buf, uint32_t len, void *ctx)<br>
++void SoapyRTLSDR::rx_sync_operation(void)<br>
+ {<br>
+-=C2=A0 =C2=A0 //printf(&quot;_rx_callback\n&quot;);<br>
+-=C2=A0 =C2=A0 SoapyRTLSDR *self =3D (SoapyRTLSDR *)ctx;<br>
+-=C2=A0 =C2=A0 self-&gt;rx_callback(buf, len);<br>
+-}<br>
++=C2=A0 =C2=A0 int rxSize;<br>
++=C2=A0 =C2=A0 unsigned char *rxBuf =3D new unsigned char[bufferLength];<b=
r>
+ <br>
+-void SoapyRTLSDR::rx_async_operation(void)<br>
+-{<br>
+-=C2=A0 =C2=A0 //printf(&quot;rx_async_operation\n&quot;);<br>
+-=C2=A0 =C2=A0 rtlsdr_read_async(dev, &amp;_rx_callback, this, asyncBuffs,=
 bufferLength);<br>
+-=C2=A0 =C2=A0 //printf(&quot;rx_async_operation done!\n&quot;);<br>
++=C2=A0 =C2=A0 //printf(&quot;rx_sync_operation\n&quot;);<br>
++=C2=A0 =C2=A0 while (_rxRunning) {<br>
++=C2=A0 =C2=A0 =C2=A0 =C2=A0 if (rtlsdr_read_sync(dev, (void *)rxBuf, buff=
erLength, &amp;rxSize) &lt; 0)<br>
++=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 break;<br>
++=C2=A0 =C2=A0 =C2=A0 =C2=A0 rx_callback(rxBuf, rxSize);<br>
++=C2=A0 =C2=A0 }<br>
++=C2=A0 =C2=A0 //printf(&quot;rx_sync_operation done!\n&quot;);<br>
++<br>
++=C2=A0 =C2=A0 delete[] rxBuf;<br>
+ }<br>
+ <br>
+ void SoapyRTLSDR::rx_callback(unsigned char *buf, uint32_t len)<br>
+@@ -316,11 +319,12 @@ int SoapyRTLSDR::activateStream(<br>
+=C2=A0 =C2=A0 =C2=A0resetBuffer =3D true;<br>
+=C2=A0 =C2=A0 =C2=A0bufferedElems =3D 0;<br>
+ <br>
+-=C2=A0 =C2=A0 //start the async thread<br>
+-=C2=A0 =C2=A0 if (not _rx_async_thread.joinable())<br>
++=C2=A0 =C2=A0 //start the sync thread<br>
++=C2=A0 =C2=A0 if (not _rx_sync_thread.joinable())<br>
+=C2=A0 =C2=A0 =C2=A0{<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0rtlsdr_reset_buffer(dev);<br>
+-=C2=A0 =C2=A0 =C2=A0 =C2=A0 _rx_async_thread =3D std::thread(&amp;SoapyRT=
LSDR::rx_async_operation, this);<br>
++=C2=A0 =C2=A0 =C2=A0 =C2=A0 _rxRunning =3D true;<br>
++=C2=A0 =C2=A0 =C2=A0 =C2=A0 _rx_sync_thread =3D std::thread(&amp;SoapyRTL=
SDR::rx_sync_operation, this);<br>
+=C2=A0 =C2=A0 =C2=A0}<br>
+ <br>
+=C2=A0 =C2=A0 =C2=A0return 0;<br>
+@@ -329,10 +333,10 @@ int SoapyRTLSDR::activateStream(<br>
+ int SoapyRTLSDR::deactivateStream(SoapySDR::Stream *stream, const int fla=
gs, const long long timeNs)<br>
+ {<br>
+=C2=A0 =C2=A0 =C2=A0if (flags !=3D 0) return SOAPY_SDR_NOT_SUPPORTED;<br>
+-=C2=A0 =C2=A0 if (_rx_async_thread.joinable())<br>
++=C2=A0 =C2=A0 if (_rx_sync_thread.joinable())<br>
+=C2=A0 =C2=A0 =C2=A0{<br>
+-=C2=A0 =C2=A0 =C2=A0 =C2=A0 rtlsdr_cancel_async(dev);<br>
+-=C2=A0 =C2=A0 =C2=A0 =C2=A0 _rx_async_thread.join();<br>
++=C2=A0 =C2=A0 =C2=A0 =C2=A0 _rxRunning =3D false;<br>
++=C2=A0 =C2=A0 =C2=A0 =C2=A0 _rx_sync_thread.join();<br>
+=C2=A0 =C2=A0 =C2=A0}<br>
+=C2=A0 =C2=A0 =C2=A0return 0;<br>
+ }<br>
</blockquote></div><div><br clear=3D"all"></div><br><span class=3D"gmail_si=
gnature_prefix">-- </span><br><div dir=3D"ltr" class=3D"gmail_signature"><d=
iv dir=3D"ltr"><a href=3D"https://buzzdeee.reitenba.ch" target=3D"_blank">h=
ttps://buzzdeee.reitenba.ch</a></div></div>

--000000000000e27ce20658380b9a--