Author Topic: BASS_Encode_ServerInit  (Read 721 times)

Ed1966

  • Posts: 248
BASS_Encode_ServerInit
« on: 6 Oct '23 - 06:25 »
Hi!

I want to play music here in my own network. Now I see BASS_Encode_ServerInit to be able to do that?
Unfortunately I don't know how it all works. See here small pieces of source what I did. The original URL (http://icecast.vrtcdn.be) at BASS_StreamCreateURL plays nicely.
What am I doing wrong here?

Code: [Select]
function MyServerClientConnectCb(handle: HENCODE; connect: BOOL; client: PAnsiChar; headers: PAnsiChar;
  user1:Pointer): BOOL; {$IFDEF MSWINDOWS}stdcall{$ELSE}cdecl{$ENDIF};
begin
  Result := True;
end;

procedure TForm1.Button2Click(Sender: TObject);
const
  BufSz = 256;
var
  stream: HSTREAM;
  encoder: HENCODE;
  srv: PAnsiChar;
  channel: HSTREAM;
begin
  stream := BASS_StreamCreateFile(False, PChar('1.mp3'), 0, 0, BASS_UNICODE {or BASS_STREAM_DECODE }or BASS_SAMPLE_FLOAT);
  Error('BASS_StreamCreateFile' + BASS_ErrorGetCode().ToString);

  encoder := BASS_Encode_MP3_Start(stream, nil, BASS_ENCODE_AUTOFREE or BASS_ENCODE_FP_24BIT or BASS_UNICODE or BASS_ENCODE_CAST_NOLIMIT, nil, nil);
  Error('BASS_Encode_MP3_Start' + BASS_ErrorGetCode().ToString);

  srv := '127.168.1.0'; // '127.0.0.1'; // '8000';
  BASS_Encode_ServerInit(encoder, srv, BufSz * 2, BufSz * 2, 0{BASS_ENCODE_SERVER_META}, MyServerClientConnectCb, nil);
  Error('BASS_Encode_ServerInit' + BASS_ErrorGetCode().ToString);

  // WORKS >>> channel := BASS_StreamCreateURL('http://icecast.vrtcdn.be/mnm_90s00s-high.mp3'{'http://127.168.1.0'}, 0, BASS_STREAM_BLOCK or BASS_UNICODE, nil, nil);

  // HERE NOT WORKING
  channel := BASS_StreamCreateURL('http://127.168.1.0', 0, BASS_STREAM_BLOCK or BASS_UNICODE, nil, nil);
  Error('BASS_StreamCreateURL' + BASS_ErrorGetCode().ToString); // Errorcode 2 (BASS_ERROR_FILEOPEN)

  BASS_ChannelPlay(channel, False);
  Error('BASS_ChannelPlay' + BASS_ErrorGetCode().ToString);
end;

Regards,
Eduard.

Ian @ un4seen

  • Administrator
  • Posts: 26269
Re: BASS_Encode_ServerInit
« Reply #1 on: 6 Oct '23 - 12:41 »
Try including a port number in your BASS_Encode_ServerInit call, and then also include it in your BASS_StreamCreateURL call. If you don't specify a port number then BASS_Encode_ServerInit will choose a random available one. Please see the BASS_Encode_ServerInit documentation for further details.

Ed1966

  • Posts: 248
Re: BASS_Encode_ServerInit
« Reply #2 on: 6 Oct '23 - 14:08 »
Hi!

Code: [Select]
  srv := '127.168.1.0:8000';
  BASS_Encode_ServerInit(encoder, srv, BufSz * 2, BufSz * 2, BASS_ENCODE_SERVER_META, MyServerClientConnectCb, nil);
  Error('BASS_Encode_ServerInit' + BASS_ErrorGetCode().ToString);

  // WORKS!! channel := BASS_StreamCreateURL('http://icecast.vrtcdn.be/mnm_90s00s-high.mp3'{'http://127.168.1.0'}, 0, BASS_STREAM_BLOCK or BASS_UNICODE, nil, nil);
  channel := BASS_StreamCreateURL('http://127.168.1.0:8000', 0, BASS_STREAM_BLOCK or BASS_UNICODE, nil, nil);
  Error('BASS_StreamCreateURL' + BASS_ErrorGetCode().ToString);

  // BASS_ERROR_FILEFORM  = 41;   // unsupported file format

Now I get unsupported file format.
More hints?
And must i do something else beside this piece of code? Install other software to open ports?
I really don't know.

Regards,
Eduard.

Ian @ un4seen

  • Administrator
  • Posts: 26269
Re: BASS_Encode_ServerInit
« Reply #3 on: 6 Oct '23 - 15:02 »
Are you calling BASS_StreamCreateURL straight after BASS_Encode_ServerInit, as in that code? If so, the server might not have received any data from the encoder yet. Try adding a delay there. Also call BASS_ChannelPlay on the encoder's source (stream) first, as nothing will be encoded before that.

Ed1966

  • Posts: 248
Re: BASS_Encode_ServerInit
« Reply #4 on: 6 Oct '23 - 18:27 »
Super. That works great to listen to music everywhere in my network. Super thanks.
 :) :) :) :) :)  :-\ :-\

O wait. This is only loop this PC.  :o

How can I for example use http://192.168.2.30:8000 to listen from all network pc's ?

BASS_Encode_ServerInit gives BASS_ERROR_ILLPARAM!

Thanks.
« Last Edit: 6 Oct '23 - 19:18 by Ed1966 »

Chris

  • Posts: 2222
Re: BASS_Encode_ServerInit
« Reply #5 on: 6 Oct '23 - 22:20 »
Hi
a other possible way is something like this
 
Code: [Select]
Fstream := BASS_StreamCreateFile(False, PWideChar('1.mp3'), 0, 0, BASS_UNICODE or BASS_SAMPLE_FLOAT );
  BASS_ChannelSetAttribute(FStream,Bass_Attrib_Vol,0); // we want to hear the urlstream
  bass_ChannelPlay(fstream,false);
  Fencoder := BASS_Encode_MP3_Start(Fstream, '-b 256',  BASS_ENCODE_NOHEAD, nil, nil);
  Server_Init := BASS_Encode_ServerInit(Fencoder, PAnsiChar('192.168.178.10:9000/stream1'), 64000, 64000, BASS_ENCODE_SERVER_META, MyServerClientConnectCb, nil);

So every PC in your Network can access the stream via "BASS_StreamCreateURL(PWideChar('http://192.168.178.10:9000/stream1'), 0, BASS_UNICODE, nil, nil);"

but requirements are that there is no Block from the Firewall on the Stream PC




Ed1966

  • Posts: 248
Re: BASS_Encode_ServerInit
« Reply #6 on: 7 Oct '23 - 03:42 »
Hi!

That don't work but I was thinking and mistaking.
My IP server pc is 192.168.2.4 (Looked up)
Solution here is: 192.168.2.4:9000/stream1

Now all works fine  ;) :D

Thanks Ian and Chris.