Outerra forum

Please login or register.

Login with username, password and session length
Advanced search  

News:

Download Outerra Tech Demo. Unofficial Outerra Discord server, MicroProse Discord server for OWS.

Author Topic: embed live webaudiostreams in outerra  (Read 9241 times)

fly77

  • Outerra Master Modder
  • Hero Member
  • *****
  • Posts: 1761
embed live webaudiostreams in outerra
« on: March 22, 2022, 02:03:43 pm »

Here is an example mod that retrieves web audiostreams from the web and plays them inside outerra.
Only web audiostreams that "autoplay" when the URL of the stream is pasted into a browser do work.

The mod plays just one fixed radiostation set in the first line of the script "webAudioStreamExample.js"
and its purpose is just to show how commands can be used inside mod scripts to embed live web audiostreams inside outerra.


By inspecting the javascript file "webAudioStreamExample.js" that you find in the
"username/Outerra/packages/fly77/radiolina"  folder you can learn which commands are available and how to use them.
Given the purpose of this mod the script is intentionally kept very basic.


note that the commands require my fly77_plugin.dll to be installed in outerra (see below).


Download from here:

https://drive.google.com/drive/folders/1tSfnBGLoc-DPQ_tRS_H75UZV_NYmn2ky?usp=sharing


installation:
there are two files : fly77_plugin.dll  and radiolina.otx
1) drop fly77_plugin.dll  into Anteworld/plugins folder  ! (not in the username/Outerra/plugins one)
2) click on self-installing radiolina.otx file



use:
you can find the mod under vehicles as "radiolina"
spawn it and while still inside the radio press L to switch the radio ON and L again to switch it off.
You will hear the fixed web audiostream of WBGO Jazz 88.3 FM - Newark, NJ  radio
which has audiostream URL

http://wbgo.streamguys.net/wbgo96
 
you can hear the same by just pasting this URL in a browser.
Note that it will autoplay without requiring you to press any play button.

You can experiment by substituting different web audiostream URLs in the first line of the mod script




« Last Edit: March 23, 2022, 01:58:49 am by fly77 »
Logged

andfly

  • Sr. Member
  • ****
  • Posts: 347
Re: embed live webaudiostreams in outerra
« Reply #1 on: March 23, 2022, 05:51:27 am »

Very, very interesting and well done!
Effective for the intended purpose.
Thanks for sharing.

And now ... (huh, huh ... were you hoping to get away with it?) Million-dollar question ...
I noticed that, in addition to commanding the execution of the audio stream, you are also able to send get requests and obtain data in response:
$ plugin.get_web_audiostream_info ();
$ plugin.get_web_playlist_info ();
$ plugin.get_web_media_info ();
$ plugin.get_waveaudio_device_info ();

All these requests are addressed in order to obtain objects with the characteristics required by the audio stream.

Would it be possible to write a "universal" function that makes a "get" call to a website and gets json data or a text string in response, at the user's discretion?

Let me explain better with an example, for me, very current.
In the simulation program of the ISS I need to obtain the starting data for the calculation of the position and speed of the station.
Through the plugin I execute a command:  system (" curl -s -o "+ Path +" iss2.txt https://api.wheretheiss.at/v1/satellites/25544/tles ");
Basically I ask, through a system call, to the windows program curl.exe, to make a "get" call to the "wheretheiss.at" site and to write the answer in the "iss2.txt" file. Then I read the file through the plugin and transport the data that interests me "cleaned up" in the main program.
All this is extremely inelegant and, even if it achieves the intended purpose, it unnecessarily complicates the procedure.
Moreover, it causes the program to be interrupted for about a second, waiting for the answer and for the conclusion of the "system" call.

Unfortunately, I haven't found another more direct way.
The study of the routines that communicate with the Web in the Outerra API and the attempt to include the CURL project in the plugin have not been successful, due to my lack of knowledge of the C ++ language. Again I had to "get around" the problem with a trick.

A universal "get" function would be very useful to anyone wishing to communicate with the Web from within Outerra and without consulting external programs.

Thank you for your attention.   :)
Logged
I do not know the English language. I use Google Translate. I hope it's all understandable.

fly77

  • Outerra Master Modder
  • Hero Member
  • *****
  • Posts: 1761
Re: embed live webaudiostreams in outerra
« Reply #2 on: March 23, 2022, 11:56:27 am »

..And now ... (huh, huh ... were you hoping to get away with it?) Million-dollar question ...
...Would it be possible to write a "universal" function that makes a "get" call to a website and gets json data or a text string in response, at the user's discretion?

huh..difficult but fascinating.. I'll try to include the curl inside the c++ plugin
This link seems to provide an example. I'll let you know

http://www.cplusplus.com/forum/windows/36638/
Logged

fly77

  • Outerra Master Modder
  • Hero Member
  • *****
  • Posts: 1761
Re: embed live webaudiostreams in outerra
« Reply #3 on: March 24, 2022, 04:07:44 am »

The first step is to get curl built and seen in visual studio (I use visual studio 2019 comunity edition)
This worked perfectly for me.
https://stackoverflow.com/questions/53861300/how-do-you-properly-install-libcurl-for-use-in-visual-studio-2017
since for outerra we need the 64 version of curl the commands I did in cmd window are :

    Get latest vcpkg zip file from https://github.com/microsoft/vcpkg/releases (e.g. https://github.com/microsoft/vcpkg/archive/2019.09.zip) and extract it to a folder of your choice (e.g. C:\vcpkg\)
    Open Developer Command Prompt and cd to C:\vcpkg\
    Run bootstrap-vcpkg.bat
    Run vcpkg.exe integrate install
    Run vcpkg install curl:x64-windows
    Create a new C++ project in Visual Studio and you're ready to go


Then you need to set the include and library directories as well as linker additional library dependencies in visual studio for your plugin :

In Project Properties -> VC++ Directories -> Include Directories add C:\curl\builds\libcurl-vc-x86-release-static-ipv6-sspi-winssl\include\
In Project Properties -> VC++ Directories -> Library Directories add C:\curl\builds\libcurl-vc-x86-release-static-ipv6-sspi-winssl\lib\ there
In Project Properties -> Linker -> Input -> Additional Dependencies add libcurl_a.lib, Ws2_32.lib, Crypt32.lib, Wldap32.lib and Normaliz.lib

finally in the plugin hpp obviously add the include:

#define CURL_STATICLIB
#include "CURL/curl.h"

The plugin compiles fine in 64 bit.

now comes the other part ..what to do with it....I'll let you know if I can create the curl HTML GET command there..



« Last Edit: March 24, 2022, 04:28:33 am by fly77 »
Logged

andfly

  • Sr. Member
  • ****
  • Posts: 347
Re: embed live webaudiostreams in outerra
« Reply #4 on: March 26, 2022, 05:48:33 am »

I was going to reply with "curl" already up and running but ... I can't find the time and I have to keep putting it off.
In the meantime, however, I would like to congratulate you on the excellent and very fast work.
With such detailed instructions I think it will all be very easy.

And, of course, thank you so much !!    :D :D
Logged
I do not know the English language. I use Google Translate. I hope it's all understandable.

fly77

  • Outerra Master Modder
  • Hero Member
  • *****
  • Posts: 1761
Re: embed live webaudiostreams in outerra
« Reply #5 on: March 26, 2022, 10:39:45 am »

...I would like to congratulate you on the excellent and very fast work.
With such detailed instructions I think it will all be very easy.
And, of course, thank you so much !!    :D :D

Thank you ..actually its a good opportunity for me to learn some more c++...thank you for the idea to use curl in outerra.
Of course we are all busy with life and so am I. But if I find time to use it ..at least to retrieve the ISS position ..I will certainly try. Then you could use a command like say   fly77plugin.getISSposition to add to your mod.

 
Logged

andfly

  • Sr. Member
  • ****
  • Posts: 347
Re: embed live webaudiostreams in outerra
« Reply #6 on: March 30, 2022, 09:26:24 am »


The plugin compiles fine in 64 bit.

No way.  >:(
I have now installed CURL more than a dozen times.

With both methods indicated in:
https://stackoverflow.com/questions/53861300/how-do-you-properly-install-libcurl-for-use-in-visual-studio-2017

With your method that summarizes and integrates the two systems.

And with a new way found on the web, specific to Visual Studio 2019:
https://medium.com/@farhabihelal/how-to-set-up-libcurl-on-visual-studio-2019-a9fdacce6945

Nothing to say for the installation, which goes well until the end.

The problem comes later.

If I create a new project and insert only the code that these sites indicate as an example, the compilation happens smoothly and is successful.

If, on the other hand, I set the include to CURL in my dll project for Outerra, no error is reported to me during the code writing phase, but during the compilation phase the occurrence of a considerable number of errors does not allow me the success of the compilation.

It almost seems that there is a "safety brake" that does not allow the intrusion of new libraries other than those provided by Outerra. Obviously this is a hypothesis without any basis and therefore it is certainly my inexperience that does not produce the desired result.

I must say that, to create the dll project, I used the example_plugin published by Uriah
in June 2017  (which, perhaps, imposes security restrictions)
https://forum.outerra.com/index.php?topic=3738.0
to which I added my functions and which, working perfectly, I have never found reason to abandon (also because I have never tried to define a project in C ++, for a dll on Outerra, totally from scratch and I don't know if, with my little knowledge, I may be able to do it).

This is probably the right time to give it a try ...

I would just be curious to know if CURL works for your project that compiles the dll for Outerra or if you also find difficulties in the compilation phase.

Thank you  :)
« Last Edit: March 30, 2022, 12:43:37 pm by andfly »
Logged
I do not know the English language. I use Google Translate. I hope it's all understandable.

fly77

  • Outerra Master Modder
  • Hero Member
  • *****
  • Posts: 1761
Re: embed live webaudiostreams in outerra
« Reply #7 on: March 30, 2022, 01:13:27 pm »

As a base for my plugin I used the example/vehicle_plugin code from github https://github.com/Outerra/anteworld/tree/master/example/vehicle_plugin
as it is certainly more up to date than uriah's version. I cloned the whole master folder from github





as for including curl in the dll I have no problems so far in compiling the dll , even by using some curl commands found in those posts
like for example he code shown below ...obviously you can't use print and other console commands as its not a console application so I just commented them out...just as a check if I can compile everything

Code: [Select]
ifc_fn void simplugin::curlGet()
{

CURL* curl;
CURLcode res;

curl = curl_easy_init();
if (curl) {
curl_easy_setopt(curl, CURLOPT_URL, "http://example.com/");

/* Perform the request, res will get the return code */
res = curl_easy_perform(curl);
/* Check for errors */
if (res != CURLE_OK)
//fprintf(stderr, "curl_easy_perform() failed: %s\n",curl_easy_strerror(res));

/* always cleanup */
curl_easy_cleanup(curl);
}



}

I get  lots of warning messages but no error and compilation goes fine.
 
be careful : it seems the whole preparation procedure of visual studio for setting library and include paths in visual studio seems
must be done with the plugin selected in the right pane of visual studio - as shown in my last screenshot - not applying those paths to the whole solution.
Idk if thats the problem or what else, but it seems to me setting the right library and include paths for the right code is the most important first thing to get right..also use the most updated plugin code from
outerra github..you never know.....if you don't want to abandon your old plugin you can make a new plugin naming it differently ..just to get the curl functionality cleanly into outerra

But as I said so far I haven't done anything useful with it. Need still to try.


« Last Edit: March 30, 2022, 01:26:39 pm by fly77 »
Logged

andfly

  • Sr. Member
  • ****
  • Posts: 347
Re: embed live webaudiostreams in outerra
« Reply #8 on: March 30, 2022, 01:30:16 pm »

As I imagined ...
The problems are in my plugin or its settings.

It is time to study a little and rewrite everything (if I find the time).

Thanks, as always, for your prompt reply and helpful advice!  :)
Logged
I do not know the English language. I use Google Translate. I hope it's all understandable.

fly77

  • Outerra Master Modder
  • Hero Member
  • *****
  • Posts: 1761
Re: embed live webaudiostreams in outerra
« Reply #9 on: March 30, 2022, 03:09:28 pm »

hmm...while I can compile the plugin for the moment when there is any curl code in the plugin when i run outerra and just call the plugin interface it no longer can get the plugin.
So also me I am stuck ..allthough at a different point  :'(
Logged