Author Topic: BASSenc server - allow source connections  (Read 165 times)

fmcoder

  • Posts: 485
BASSenc server - allow source connections
« on: 22 Dec '22 - 18:28 »
Hi Ian,

The server in bassenc gained lots of improvements over the time, many thanks for that! It's already pretty good, but lacks one important feature that streaming servers typically have: external source connections. Are there any plans on implementing this?

Ian @ un4seen

  • Administrator
  • Posts: 25054
Re: BASSenc server - allow source connections
« Reply #1 on: 23 Dec '22 - 12:02 »
There weren't any plans for the BASSenc server to have that feature, as it's already covered by Icecast/Shoutcast, and it doesn't really fit the current model of a server being assigned to an encoder. Do you have a scenario in mind where Icecast/Shoutcast don't cover it?

If it's needed now, I think it would be possible to implement by using a PCM encoder (BASS_ENCODE_PCM) to feed pre-encoded data to the server, like in this example from the BASS_Encode_ServerInit docs:

Code: [Select]
dummy = BASS_StreamCreate(44100, 1, BASS_STREAM_DECODE, STREAMPROC_DUMMY, NULL); // create a dummy stream to host the encoder
encoder = BASS_Encode_Start(dummy, NULL, BASS_ENCODE_PCM | BASS_ENCODE_NOHEAD, NULL, NULL); // setup the PCM encoder
BASS_Encode_ServerInit(encoder, "8000", 64000, 64000, 0, NULL, NULL); // start the server
...
BASS_Encode_Write(encoder, data, length); // feed encoded data to the encoder/server (repeat periodically)

In this case, the encoded data would be coming from a socket.

fmcoder

  • Posts: 485
Re: BASSenc server - allow source connections
« Reply #2 on: 23 Dec '22 - 17:20 »
Yes, Shoutcast/Iceast cover it in full, but the idea is to avoid this dependency.

Before bassenc server was introduced, it was required to use server software like Icecast to transfer audio between remote instances. Now, bassenc covers listener connections, which is convenient because users don't need to install Icecast anymore. Still, the scenario when source connections are needed, require such installation, that's why I asked if maybe there are plans on implementing it.

In this case, the encoded data would be coming from a socket.
Looks like I'm missing something, but how this allows an external program to connect as a streaming source? Is it supposed that the data that is being written with BASS_Encode_Write is received via TCP socket earlier?

Ian @ un4seen

  • Administrator
  • Posts: 25054
Re: BASSenc server - allow source connections
« Reply #3 on: 23 Dec '22 - 18:00 »
In this case, the encoded data would be coming from a socket.
Looks like I'm missing something, but how this allows an external program to connect as a streaming source? Is it supposed that the data that is being written with BASS_Encode_Write is received via TCP socket earlier?

Yes. For example, there could be a "recv" function call before BASS_Encode_Write:

Code: [Select]
length = recv(socket, data, length, 0); // receive encoded data from socket
if (length > 0) BASS_Encode_Write(encoder, data, length); // feed it to the encoder/server

Note you would need to setup the socket yourself, eg. the socket handle could come from an earlier "accept" function call (when a source connected).

fmcoder

  • Posts: 485
Re: BASSenc server - allow source connections
« Reply #4 on: 25 Dec '22 - 08:50 »
Interesting, thanks. The only downside I currently see is that it wouldn't be possible to run this on the same port where listeners connect.