#1 2025-04-11 16:40:31

fredvs
Member
Registered: 2025-04-11
Posts: 10

mORMot and web stream of mp3 and acc radios?

Hello!

Congratulation for this great project.

uos (United Openlib of Sound) use fpc TFPHTTPClient to do audio from web radios.
It works mostly great on Linux but some http.Http.Head() fail to connect (but using curl it is ok) and with Windows there are problems with     
Could not initialize openssl library.
Also, there are problems with:

         Http.AddHeader('Range', 'bytes=0-1023');
         Http.Get(URL, ms);

The 'Range' is not done, all is downloading.

This is the unit that does the work for web-streams:

https://github.com/fredvs/uos/blob/main … thread.pas

Should it be possible to use mORMot to do this job and would it be complicated to "translate" the code to be compatible with mORMot?

Thanks.

Fre;D

Offline

#2 2025-04-11 16:50:45

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,952
Website

Re: mORMot and web stream of mp3 and acc radios?

You could indeed use mORMot 2 to have a HTTP client.

There are several classes... I would perhaps just use the THttpClientSocket class.
On Windows, it could use SChannel for HTTPS so no OpenSSL is needed.
Reconnections should be automatic, like redirection and such.
You even have a WGET-like feature if huge content is needed (maybe for podcasts, not web stream).
It can support proxy and ranges too.

But note that we have limited BSD testing yet - beside MacOS which is well tested.

Offline

#3 2025-04-11 17:43:09

fredvs
Member
Registered: 2025-04-11
Posts: 10

Re: mORMot and web stream of mp3 and acc radios?

OK, perfect.

Are there simple demos THttpClientSocket to do http.get and http.head?
For example in the uos project to access web stream, is it possible to use mormot even for console or MSEgui/fpGUI apps?

Offline

#4 2025-04-11 21:33:30

fredvs
Member
Registered: 2025-04-11
Posts: 10

Re: mORMot and web stream of mp3 and acc radios?

Hello.

OK, I think that the conversion done with my new friend AI Gork seems promising.

But the code fails at linking with this:

/usr/bin/ld: cannot find ../../static/x86_64-linux/sha512-x64sse4.o: No such file or directory
/usr/bin/ld: cannot find ../../static/x86_64-linux/crc32c64.o: No such file or directory
/usr/bin/ld: cannot find ../../static/x86_64-linux/libdeflatepas.a: No such file or directory

I did copy the files in  /home/fred/swp_work/src/mormot2static/x86_64-linux and used the fpc parameter -Fl/home/fred/swp_work/src/mormot2static/x86_64-linux but still same error.
Sadly my friend AI Gork is tired, it cannot help me and I dont see what to do.

Last edited by fredvs (2025-04-11 23:08:07)

Offline

#5 2025-04-11 21:41:36

fredvs
Member
Registered: 2025-04-11
Posts: 10

Re: mORMot and web stream of mp3 and acc radios?

Ok,ok, ok,

>I did copy the files in  /home/fred/swp_work/src/mormot2static/x86_64-linux and used the fpc parameter -Fl/home/fred/swp_work/src/mormot2static/x86_64-linux but still same error.
>Sadly my friend AI Gork is tired, it cannot help me and I dont see what to do.

Copying the files there: /home/fred/static did the job (a few strange but ok).

But it does not work so I have to jump into mormot and try to understand why it does not work yet.

Offline

#6 2025-04-11 22:08:47

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,952
Website

Re: mORMot and web stream of mp3 and acc radios?

Please follow the forum rules and don't post code directly in the forum thread.

Install mORMot as a Lazarus package, as documented.

Offline

#7 2025-04-11 23:01:27

fredvs
Member
Registered: 2025-04-11
Posts: 10

Re: mORMot and web stream of mp3 and acc radios?

Some news from the front.

I did try to access a web audio mp3 radio:  http://icecast.radiofrance.fr/fip-midfi.mp3
Tested with curl and it access.

Here the mormot code used to try to access it:

uses
  mormot.net.client,
  mormot.core.base,
...
    Writeln('Testing fallback stream: http://icecast.radiofrance.fr/fip-midfi.mp3'); // Debug
    URL := 'http://icecast.radiofrance.fr/fip-midfi.mp3';
    HttpHeaders := 'User-Agent: Mozilla/5.0';
    try
      Writeln('Sending fallback GET request to: ', URL); // Debug
      Writeln('Headers sent: ', HttpHeaders); // Debug
      Status := Http.Request(URL, 'GET', 0, HttpHeaders, '', HttpHeaders, False);
      Writeln('Fallback GET Status: ', Status); // Debug
      if Status = 200 then
      begin
        Response := Http.Content;
        Writeln('Fallback Content length: ', Length(Response)); // Debug
      end
      else
        Writeln('Fallback GET failed with status: ', Status); // Debug
    except
      on E: Exception do
      begin
        Writeln('Fallback GET Exception: ', E.Message); // Debug
      end;
    end; 

--------------------

But I get this as debug:

Testing fallback stream: http://icecast.radiofrance.fr/fip-midfi.mp3
Sending fallback GET request to: http://icecast.radiofrance.fr/fip-midfi.mp3
Headers sent: User-Agent: Mozilla/5.0
Fallback GET Status: 666
Fallback GET failed with status: 666
----------------------
What did I wrong?

Offline

#8 2025-04-11 23:03:16

fredvs
Member
Registered: 2025-04-11
Posts: 10

Re: mORMot and web stream of mp3 and acc radios?

ab wrote:

Please follow the forum rules and don't post code directly in the forum thread.

Ooops, I did not know this, but without code it is difficult to explain the problem.

ab wrote:

Install mORMot as a Lazarus package, as documented.

I dont use Lazarus, sorry.

Last edited by fredvs (2025-04-11 23:36:17)

Offline

#9 2025-04-11 23:17:42

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,952
Website

Re: mORMot and web stream of mp3 and acc radios?

But you use FPC, right?

And you are confusing the URI and the resource name.

Offline

#10 2025-04-11 23:21:15

fredvs
Member
Registered: 2025-04-11
Posts: 10

Re: mORMot and web stream of mp3 and acc radios?

Yes, I am using FPC 3.2.2.

ab wrote:

And you are confusing the URI and the resource name.

Hum, it is totally possible because I dont know what is URI (I know URL) and what is resource name.
And also, I confess it, the code was done by Gork AI.

Last edited by fredvs (2025-04-11 23:33:53)

Offline

#11 2025-04-11 23:42:11

fredvs
Member
Registered: 2025-04-11
Posts: 10

Re: mORMot and web stream of mp3 and acc radios?

Ok, a fast ask gives: The main difference is in what they do: URIs identify resources, while URLs locate them.

So, the code is for URI, and it use a URL, is it so (or reverse)?

Offline

#12 2025-04-12 02:35:06

fredvs
Member
Registered: 2025-04-11
Posts: 10

Re: mORMot and web stream of mp3 and acc radios?

After a looong white night, I am finally be able to connect the url (or uri) and get the header of the audio stream:

Http := THttpClientSocket.Create(5000);
   if Pos('http://', URL) = 1 then
    Delete(URL, 1, 7);
    Host := Copy(URL, 1, Pos('/', URL) - 1);
    Resource := Copy(URL, Pos('/', URL), MaxInt);
    if Resource = '' then
    Resource := '/';
    Http.Open(Host, '80');
    Http.Request(Resource, 'GET', 0, HttpHeaders, '', HeadersOut, True);
     Response := Http.Content;
   
I will stop now and attack the GET of the audio stream via pipe later.
(I you have advice's, they are welcome).

Last edited by fredvs (2025-04-12 02:38:27)

Offline

#13 2025-04-12 07:52:54

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,952
Website

Re: mORMot and web stream of mp3 and acc radios?

You have TUri for parsing the URL/URI.
And THttpClientSocket.OpenUri() to avoid parsing.

Look at TNetworkProtocols.RunPeerCacheDirect
or THttpClientSocketWGet.WGet for usage of this method.

Offline

#14 2025-04-12 14:25:16

fredvs
Member
Registered: 2025-04-11
Posts: 10

Re: mORMot and web stream of mp3 and acc radios?

ab wrote:

You have TUri for parsing the URL/URI.
And THttpClientSocket.OpenUri() to avoid parsing.

Look at TNetworkProtocols.RunPeerCacheDirect
or THttpClientSocketWGet.WGet for usage of this method.


Many thanks, I will jump deeply into it.
Does it exist demos of this?

Offline

Board footer

Powered by FluxBB