Questions about internet radio streaming

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
41 messages Options
123
Reply | Threaded
Open this post in threaded view
|

Re: Questions about internet radio streaming

fredvs
Administrator
This post was updated on .
fredvs wrote
A other solution, that I have used many times (with always sucess) is to... ask it to mpg123 forum.
---> https://sourceforge.net/p/mpg123/bugs/248/

[EDIT] Huh, I think that the problem is how to deal with icy_meta in:

 function mpg123_icy(mh: Tmpg123_handle; var icy_meta: PPChar) : integer.
 If result = 0 --> all ok, otherwise errors.

Because when I connect to http://stream-uk1.radioparadise.com/mp3-128
The sound is fluent and, after each 10 seconds -->
mpg123_icy(HandleSt, icy_data) --> result = 0 --> so it seems ok.

But --> writeln(icy_data) --> nothing --> ;-(

Fre;D
Reply | Threaded
Open this post in threaded view
|

Re: Questions about internet radio streaming

Dibo
I have looked at your code in mpg123 forum. You have to add icy header without "Accept:". Like this:
Http.RequestHeaders.Add('Icy-MetaData:1');
Reply | Threaded
Open this post in threaded view
|

Re: Questions about internet radio streaming

Dibo
So I changed thread:

    Http.RequestHeaders.Clear;
    Http.RequestHeaders.Add('Icy-MetaData:1');
    Http.OnHeaders := @Headers;
    Http.Get(URL, FOutStream);  
New property (read only)
  public
    constructor Create(AWantedURL: String; AOutputStream: TOutputPipeStream);
    property IsRunning: Boolean read FIsRunning;
    property IcyMetaInt: Int64 read FIcyMetaInt;
... which is set in:
procedure TThreadHttpGetter.Headers(Sender: TObject);
begin
  FIcyMetaInt := StrToInt64Def(TFPHTTPClient(Sender).GetHeader(TFPHTTPClient(Sender).ResponseHeaders, 'icy-metaint'),0);
end;
Then in uos.pas after open handle:
  if err = 0 then
  begin
  writeln(mpg123_param(StreamIn[x].Data.HandleSt, MPG123_ICY_INTERVAL,
    StreamIn[x].httpget.IcyMetaInt, 0));
  StreamIn[x].Data.filename := URL ;
mpg123_param return 0 so no errors, StreamIn[x].httpget.IcyMetaInt contain also correct value but I'm still getting weird sounds and this output warnings:
After, press a key to exit...
Press a key to exit...
Note: Illegal Audio-MPEG-Header 0x2bd8ed28 at offset 33099.
Note: Trying to resync...
Note: Skipped 145 bytes in input.
Note: Illegal Audio-MPEG-Header 0xc9fffab2 at offset 65845.
Note: Trying to resync...
Note: Skipped 1 bytes in input.
Note: Illegal Audio-MPEG-Header 0xa6fffab2 at offset 98447.
Note: Trying to resync...
Maybe I'm setting param too late?
Reply | Threaded
Open this post in threaded view
|

Re: Questions about internet radio streaming

Dibo
Dibo wrote
Maybe I'm setting param too late?
Yep. Too late. Changed thread a little. Added OnIcyMetaInt event:
  public
    constructor Create(AWantedURL: String; AOutputStream: TOutputPipeStream);
    property IsRunning: Boolean read FIsRunning;
    property IcyMetaInt: Int64 read FIcyMetaInt;
    property OnIcyMetaInt: TNotifyEvent read FOnIcyMetaInt write FOnIcyMetaInt;
  end;  
Which is fired immediately when got header:
procedure TThreadHttpGetter.Headers(Sender: TObject);
begin
  FIcyMetaInt := StrToInt64Def(TFPHTTPClient(Sender).GetHeader(TFPHTTPClient(Sender).ResponseHeaders, 'icy-metaint'),0);
  if (FIcyMetaInt>0) and (FOnIcyMetaInt<>nil) then
    Synchronize(@DoIcyMetaInt);
end;
Also changed thread to not start automatically:
constructor TThreadHttpGetter.Create(AWantedURL: String; AOutputStream: TOutputPipeStream);
begin
  inherited Create(True);
  FIsRunning:=True;
  FWantedURL:=AWantedURL;
  FOutStream:=AOutputStream;
  //Start;
end;
Then in uos added thread callback
  Tuos_InStream = class(TObject)
  private
    procedure UpdateIcyMetaInterval(Sender: TObject);


procedure Tuos_InStream.UpdateIcyMetaInterval(Sender: TObject);
begin
  if Data.HandleSt<>nil then
    mpg123_param(Data.HandleSt, MPG123_ICY_INTERVAL,
        httpget.IcyMetaInt, 0);
end;
And run thread just before open:
  StreamIn[x].httpget.Start;
  CheckSynchronize(10000);
  Err :=  mpg123_open_handle(StreamIn[x].Data.HandleSt, Pointer(StreamIn[x].InPipe));
Finally weird warnings disappeared and call:
  mpg123_icy(StreamIn[x].Data.HandleSt,pc);
  if pc<>nil then
    writeln(pc);
... return
StreamTitle='The Breeders - Cannonball';StreamUrl='http://www.radioparadise.com/graphics/covers/m/B000002HDG.jpg';
But I don't like this solution (especially CheckSynchronize require). Just did this for tests. At least we know now what was a reason
Reply | Threaded
Open this post in threaded view
|

Re: Questions about internet radio streaming

Dibo
So to sum up, mpg123_param(Data.HandleSt, MPG123_ICY_INTERVAL, X) has to be called before writting into pipe
Reply | Threaded
Open this post in threaded view
|

Re: Questions about internet radio streaming

fredvs
Administrator
In reply to this post by Dibo
Dibo wrote
treamTitle='The Breeders - Cannonball';StreamUrl='http://www.radioparadise.com/graphics/covers/m/B000002HDG.jpg';
WoW, well done Dibo.


But I don't like this solution (especially CheckSynchronize require). Just did this for tests. At least we know now what was a reason
 
That is a detail, you did make it works, congrat.
Sure you will find the best layout.

At the moment I do have access only to a bad wfi point and not my working netbook.
So I will test your victory asap.

Many thanks.

Fre;D

Reply | Threaded
Open this post in threaded view
|

Re: Questions about internet radio streaming

fredvs
Administrator
In reply to this post by Dibo
Dibo wrote
procedure TThreadHttpGetter.Headers(Sender: TObject);
begin
  FIcyMetaInt := StrToInt64Def(TFPHTTPClient(Sender).GetHeader(TFPHTTPClient(Sender).ResponseHeaders, 'icy-metaint'),0);
  if (FIcyMetaInt>0) and (FOnIcyMetaInt<>nil) then
    Synchronize(@DoIcyMetaInt);
end;
Hello Dibo.

Huh, sorry but I do not catch what is DoIcyMetaInt ?

Is it a new property in  TThreadHttpGetter ?

type
TProc : procedure of object;

TThreadHttpGetter = class(TThread)
  ...
public
    DoIcyMetaInt : TProc;
 ...

Is it Tuos_InStream.UpdateIcyMetaInterval, so at creation TThreadHttpGetter --->

StreamIn[x].httpget.DoIcyMetaInt := @StreamIn[x].UpdateIcyMetaInterval ; ?

(I have try but data is not assigned with mpg123_icy(StreamIn[x].Data.HandleSt,pc); ).

 Thanks.

Fre;D
Reply | Threaded
Open this post in threaded view
|

Re: Questions about internet radio streaming

Dibo
fredvs wrote
Hello Dibo.

Huh, sorry but I do not catch what is DoIcyMetaInt ?
Ahh, sorry, forgot abotu that one:

  TThreadHttpGetter = class(TThread)
  private
    FIcyMetaInt: Int64;
    FOnIcyMetaInt: TNotifyEvent;
    FOutStream: TOutputPipeStream;
    FWantedURL: String;
    FIsRunning: Boolean;
    FTmpStream: TMemoryStream;
    procedure Data(Sender: TObject; const ContentLength, CurrentPos: Int64);
    function GetRedirectURL(AResponseStrings: TStrings): String;
    procedure Headers(Sender: TObject);
    procedure DoIcyMetaInt;  



procedure TThreadHttpGetter.DoIcyMetaInt;
begin
  if Assigned(FOnIcyMetaInt) then
    FOnIcyMetaInt(Self);
end;  
Reply | Threaded
Open this post in threaded view
|

Re: Questions about internet radio streaming

fredvs
Administrator
Thanks Dibo.

Aaargh, no more battery, ok, I will test tomorow.

Fre;D
Reply | Threaded
Open this post in threaded view
|

Re: Questions about internet radio streaming

fredvs
Administrator
In reply to this post by Dibo
Dibo wrote
fredvs wrote
Hello Dibo.

Huh, sorry but I do not catch what is DoIcyMetaInt ?
Ahh, sorry, forgot abotu that one:

  TThreadHttpGetter = class(TThread)
  private
    FIcyMetaInt: Int64;
    FOnIcyMetaInt: TNotifyEvent;
    FOutStream: TOutputPipeStream;
    FWantedURL: String;
    FIsRunning: Boolean;
    FTmpStream: TMemoryStream;
    procedure Data(Sender: TObject; const ContentLength, CurrentPos: Int64);
    function GetRedirectURL(AResponseStrings: TStrings): String;
    procedure Headers(Sender: TObject);
    procedure DoIcyMetaInt;  



procedure TThreadHttpGetter.DoIcyMetaInt;
begin
  if Assigned(FOnIcyMetaInt) then
    FOnIcyMetaInt(Self);
end;  
Hello Dibo.

OK, I have committed your advices in last commit  5e680a4..06084a5.

Sadly, the updated conswebstream demo gives always icy-data not assigned.

Fre;D
Reply | Threaded
Open this post in threaded view
|

Re: Questions about internet radio streaming

Dibo
First, I'm not sure if commit it was good idea. This was just my draft  . Also if internet stream has no support for icy-data then CheckSynchronize(10000); will freeze here for 10 seconds.
Second, how and where you call mpg123_icy()?
Reply | Threaded
Open this post in threaded view
|

Re: Questions about internet radio streaming

fredvs
Administrator
Dibo wrote
First, I'm not sure if commit it was good idea.
Maybe but it is how I work. And thanks to me to work that way : I just have a big crash on my pc and I am very happy that I did commit of my work (even if the commits are not perfect).
Also uos is open-source for everybody.
I find normal that, after asking help to fpc + mpg123 forum, if generous people gives answers, that I give this answers back to other people too.

Dibo wrote
Also if internet stream has no support for icy-data then CheckSynchronize(10000); will freeze here for 10 seconds.
In last commit, uos_AddFromURL(..) has a new parameter : ICYenabled. This is set to disable by default.
I hope that I will find the right way to make it work (if you do not want to give your secret).

Dibo wrote
Second, how and where you call mpg123_icy()?
With uos_InputUpdateICY(PlayerIndex1,InputIndex1,theicytag), 30seconds after uos_Play(PlayerIndex1);

Fre;D
Reply | Threaded
Open this post in threaded view
|

Re: Questions about internet radio streaming

Dibo
fredvs wrote
In last commit, uos_AddFromURL(..) has a new parameter : ICYenabled. This is set to disable by default.
I hope that I will find the right way to make it work (if you do not want to give your secret).
Ahh, it is fine then. I was worried that you added it as it is and it break something which worked fine so far
Reply | Threaded
Open this post in threaded view
|

Re: Questions about internet radio streaming

fredvs
Administrator
Dibo wrote
Ahh, it is fine then. I was worried that you added it as it is and it break something which worked fine so far
Like you know, connecting to Internet is a hard battle for me. So it is difficult to test-develop web stuffs.
For example, for ICY data (thanks to you, fpc-forum and Thomas of mpg123) uos has all the tools to work.
I just need some time and a (working) net-connection to finalize a working demo.

Fre;D

Reply | Threaded
Open this post in threaded view
|

Re: Questions about internet radio streaming

fmann
Hi all,

I found this very interesting Project.
My question is, is it now possible, to get Meta Information about the radio stream?
It is not completely clear after reading the post.

To have addtional Information to the well working Stream, like Title and Artist in the GUI Application would be very nice.

Regards
fmann

Reply | Threaded
Open this post in threaded view
|

Re: Questions about internet radio streaming

fredvs
Administrator
This post was updated on .
> To have addtional Information to the well working Stream, like Title and Artist in the GUI Application would be very nice.

Hello.

You may get TAG informations (like title, artist, date, album, ...)  of the streaming file (mp3 or opus) like it was a local file.
For additional infos, like radio-news,  icy-metadata, it should work but I never try it (please read previous post).

You may try the demos /uos/examples/conswebstream.lpi/prj,  simplewebplayer.lpi/prj and simplewebplayer_fpgui.lpi/prj.

Fe;D
Reply | Threaded
Open this post in threaded view
|

Re: Questions about internet radio streaming

fmann
Hi, thnaks for the reply.
The changes stated in this post are already in the Units but in project ConsoleWebStream the Tag icy is empty in Runtime.
In SimpleWebPlayer the meta Tags are not foreseen.
Is there an example project where these Information already built in?
Reply | Threaded
Open this post in threaded view
|

Re: Questions about internet radio streaming

fredvs
Administrator
> but in project ConsoleWebStream the Tag icy is empty in Runtime.

> Is there an example project where these Information already built in?

Are you talking about a example that can use/read icy tag?
https://cast.readme.io/docs/icy

If this, no, somebody with a working Internet link is welcome to test and explore it.
I have to confess that I never used icy protocol and I do not know what kind of info it gives.

I did add some code from Dibo (see previous posts) but did not test it.

If you need the meta-tags from the file itself (like artist, album, etc), you may use the "classical" way like this:

 if uos_CreatePlayer(0) then
  if uos_AddFromURL(0,pchar(the_url)) <> -1 then
  begin
  TagTitle:= uos_InputGetTagTitle(0,0);
  TagArtist:= uos_InputGetTagArtist(0,0);
  TagAlbum:= uos_InputGetTagAlbum(0,0);
  TagDate:= uos_InputGetTagDate(0,0);
  TagComment:= uos_InputGetTagComment(0,0);
  TagTag:= uos_InputGetTagTag(0,0);
  ...

Fre;D
Reply | Threaded
Open this post in threaded view
|

Re: Questions about internet radio streaming

fmann
If this is working, would be ok for me.
I´ll test it. Thank you.
Reply | Threaded
Open this post in threaded view
|

Re: Questions about internet radio streaming

fmann
Hi,

I did some testing about the Tags.
I didn´t get it working. Could it be, that this is indeed only for MP3 Files? That would be a pity, because uos for radio streaming works very well.

Any chance to get it working from your side?

Regards
123