Understanding buffer size of the TCP server inside RTL-SDR

Main forum to discuss RTL-SDR related topics.
Post Reply
Posts: 1
Joined: Thu Nov 07, 2019 8:55 am

Understanding buffer size of the TCP server inside RTL-SDR

Post by mahaju » Thu Nov 07, 2019 9:09 am

I am trying to understand a bit about how the RTL-SDR works

I am working with one from RTL-SDR.com, DVB-T+DAB+FM+SDR , RTL2832U R820T2 TCXO+BIAS T+HF, V.3 model

I am also trying to interface this with android, using the sdr-tcp-android (https://github.com/martinmarinov/rtl_tcp_andro-) library

I have managed to get things working and I can set the SDR to use direct sampling, and I am getting IQ samples from the SDR

From what I understand, once I initialize the rtl-tcp driver, it starts a TCP server in the RTL-SDR hardware, which immediately begins to send out a continuous stream of I/Q interleaved bytes, and it is our responsibility to have an appropriate TCP client to read these bytes in our buffer. I hope I understood everything correctly upto this point. I managed to get a TCP client app running in android, but I am reading 1 byte from the RTL-SDR at a time. The data I am getting from the SDR seems to be correct and I don't think I am missing any bytes, but I think I am only collecting very few number of bytes when I do this. For example, in a period of 500 milliseconds I am getting a few 10000 bytes. Am I doing this correctly? From the TCP client, should I be able to read more than 1 byte at a time? I am assuming there is a buffer in the RTL-SDR hardware which it start to fill with new data as soon as the rtl-tcp-android driver tells it to do so, and all that my tcp-client app is doing in reading off of this buffer. If my understanding is correct, is there any way to know what the size of this buffer is? At what rate does this buffer fill? If I read more than 1 byte off of this buffer at a time, is there a possibility of emptying this buffer faster than it can fill?

Posts: 135
Joined: Sat Jan 14, 2017 11:07 pm

Re: Understanding buffer size of the TCP server inside RTL-SDR

Post by hotpaw2 » Sat Nov 09, 2019 7:03 pm

Reading from a network buffer 1 byte at a time is very inefficient and unlikely to be able keep up with the high SDR raw IQ data rates. You should instead try to read at least MTU sized buffers or larger, and check the amount actually returned by the network read() call.

The RTL-SDR chip provides blocks of samples (tens of kilo-samples per block) during each USB read. The rtl_tcp code then buffers the USB data blocks, and sends out the data as a stream, which then gets broken into MTU sized network packets by the OS TCP/IP stack. If the client and server are running on the same processor, the network transfer is more efficient, but each separate read() call incurs a **lot** of overhead. So you want to minimize the number of OS calls, and read far less often than every sample or byte.

Post Reply