C++ stream server for HTML5 Audio - c++

Is it possible to have the src of an HTML5 Audio tag be a C++ program, and for the C++ program to stream audio to the audio element? For example, let's say I have an HTML5 Audio element trying to get audio from a local program like so:
<audio src='file://(path to program)'>
If it is possible, which libraries should I use? I just want to try it locally for now, so file:// is what I want.
EDIT: Setting the source as file:// won't work, so how can I tell it to get audio from the specific C++ program?

I am not sure about the C++ side of the question, but trying to embed a would-be program via file: will not work, as the browser would simply read the binary file foo.exe instead of calling it and reading in the standard output (or whatever).
Instead, for testing purposes, you would probably like to run the server locally on your machine, referring to it via localhost.

Certainly if your C++ program was stand-alone, you could write/include a mini-web server to service only audio requests that come in and then execute whatever code you wanted to in C++ to return the data.
Otherwise you could write a C++ plugin/module to an existing web server like IIS or apache and configure the web server to direct traffic for a specific url to your C++ functions to return the data. This might be a little more complicated but alot more powerful by allowing you to focus more on your audio code than worrying about handling HTTP protocol and TCP connections.
In either case then your C++ code would be referenced the same as any webserver. "<audio src='http://localhost:port/etc'>

Related

How to use WebRTC in a C++ application?

I'm trying to write a C++ command line program for peer-to-peer file transfer. My idea is to establish a connection with another machine, and send file data directly. My target platform is Windows, but interoperability with Linux and MacOS would be nice. I want this program to be standalone and not require a web browser.
I did some research and it seems that WebRTC would fit the bill, but I can't find much information on using it with C++.
Is it possible to build a standalone executable that utilizes WebRTC without requiring users to download any dependencies in order to use my program?
As the name suggests - to have the "RTC", it requires "Web" component, either in form of browser or a library.
The C++ library is quite huge and it's not a trivial task to understand and write it in a short period. Browser provides APIs in form of JavaScript calls, which are relatively easier to implement.
There might be commercial APIs in C++ available over internet.

Use Go within a Qt C++ project

Is it possible to use a Go API in a Qt C++ project?
I would like to use the following Google API written in Go: https://cloud.google.com/speech-to-text/docs/reference/libraries#client-libraries-install-go
Is it possible to use a Go API in a Qt C++ project?
It could be possible, but it might not be easy and would be very brittle to run Go and Qt code in the same process, since Go and Qt have very different thread (goroutine) and memory models.
However, Go has (in its standard library) many powerful packages to ease the development of server programs, in particular of HTTP or JSONRPC servers.
Perhaps you might consider running two different processes using inter-process communication facilities. Details are operating system specific. I assume you run Linux. Your Qt application could then start the Go program using QProcess and later communicate with it (behaving as a client to your Go specialized "server"-like program).
Then you could use HTTP or JSONRPC to remotely call your Go functions from your Qt application. You need some HTTP client library in Qt (it is there already under Qt Network, and you might also use libcurl) or some JSONRPC client library. Your Go program would be some specialized HTTP or JSONRPC server (and some Google Speech to Text client) and your Qt program would be its only client (and would start it). So your Go program would be some specialized proxy. You could even use pipe(7)-s, unix(7) sockets, or fifo(7)-s to increase the "privacy" of the communication channel.
If the Google Speech to Text API is huge (but it probably is not) you might use Go reflective or introspective abilities to generate some C++ glue code for Qt: go/ast, go/build, go/parser, go/importer, etc
BTW, it seems that Google Speech to Text protocol is using JSON with HTTP (it seems to be some Web API) and has a documented REST API, so you might directly code in C++ the relevant code doing that (of course you need to understand all the details of the protocol: relevant HTTP requests and JSON formats), without any Go code (or process). If you go that route, I recommend making your Qt (or C++) code for Google Speech to Text some separate free software library (to be able to get feedback and help from outside).

BeagleBone -> HTML -> C++ communication

I've successfully configured my beaglebone to host a website, now I'd like to enable the website viewer to communicate with a C++ program running on the beaglebone as well. I have done some reading and have a few ideas, but I don't have a solid conceptualization of the pieces that I'll need so I am looking for some advice.
I'd like two way communications, and I would like low latency, and limited restrictions on the type of data I tx/rx.
I've done some reading on WebSockets, which look to provide what I want, but I am struggling to understand how I get a WebSocket running in my C++ program, and if there's a middle man (WebSocket server?).
Please let me know if you have any advice or suggested reading for me as I work through this problem.
You might be interested in AutobahnCpp. That can be used to do the following architecture:
Your C++ Component <--WAMP-over-RawSocket--> WAMP Router <-- WAMP-over-WebSocket --> Browser
WAMP allows bidirectional real-time messaging: remote procedure calls and publish & subscribe.
E.g. you could visualize data coming from C++ in real-time in a browser. Or you could call into C++ from JavaScript in the browser.
Here are some pointers:
https://github.com/tavendo/AutobahnCpp/
http://crossbar.io/docs/Getting-started-with-Cplusplus/
https://github.com/crossbario/crossbar/blob/master/crossbar/crossbar/templates/hello/cpp/hello.cpp
https://github.com/crossbario/crossbar/blob/master/crossbar/crossbar/templates/hello/cpp/web/index.html

Receiving WebRTC call from a C++ native Windows application

I would like, from a native Windows application using C++, to receive video/audio data sent from a browser located in a remote location. It seems like WebRTC is the way to go for this.
Most information I find is about how to interact with the browser to write WebRTC apps, but it may case the data would be received by my C++ app. Is it correct that I would need to use the WebRTC Native Code package for this, which is described as being 'for browser developers'? Document is located here: http://www.webrtc.org/webrtc-native-code-package
And what if I want to send video/audio data that I generate (ie not directly coming from a webcam and microphone), would I be able to send it to the remote location browser?
Any sample code out there which does something like I'm trying to accomplish?
The wording in that link is a bit misleading. They intend people that are developing browsers to use the native code, and advise those that are developing "applications" in a browser to use the WebRTC API.
I have worked with their native code for over a year to develop an Android application that is capable of performing audio and / or video calls between other Android devices and to browsers. So, I a pretty sure that it is completely possible to to take their native code and create a Windows application (especially since they have example code that does that for Linux and Mac -- look at peerconnection client and peerconnection server for this). You might have to write and re-write code to get it to work on Windows.
As for as data that you generate. In the Android project that I worked with, we didn't rely on the Android device / system to provide us with video, we captured and sent that out our selves using the "LibJingle" / WebRTC libraries. So, I know that that is possible, as long as you provide the libraries with video data in the correct format. I would imagine that one would be able to do the same with audio, but we never fiddled with that, so I cannot say for sure.
And as for example code, I can only suggest Luke Weber's gitbug repositories. Although it is for Android, it might be of some help to look at how he interfaces with the two libraries. Probably the better code to look at is the peerconnection client stuff that comes in the "LibJingle" second of the native code. [edit]: That is located in /talk/examples/peerconection/client/ .
If you get lost from my use of "LibJingle", that will show you when I started working with all of this code. Sometime around July of 2013 they migrated "LibJingle" into the WebRTC "talk" folder. From everything that I have seen, they are the same thing, just with the location and named changed.

How to write VLC plugin that can interact with the operating system

I need to find out if it is possible and how (I do not care about the language C/C++, Lua, Python ...) to make a VLC plugin which purpose will be to be called by the VLC player and at specific times of the video stream will do some action.
The action that I need to do is to open a UDP socket and send some data read from a file that comes along with the video currently played.
I need to make something like a subtitle reader that on it's best can initialize UDP socket and send the read data to the server.
I am not sure that creation of UDP socket is possible in Lua maybe the better option will be a binary C/C++ plugin but can't find any example.
In general at the best my requirements are:
Load settings file at VLC launch
Need to be triggered by the player at specific times of the video stream
Get the file name of the source video stream
Open the file (script) with the same name but different extension
Open a UDP socket
Compose the message
Send the message
Continue the loop until the end of the video stream
Any information, example or site, link is greatly appreciated.
Looks like you would like to create a control interface module. Those are written in C/C++ within the VLC context and in turn need to be (re-) compiled for each platform you would like to target.
Have a look at the audioscrobbler module to see how to interact with the current input stream and how to retrieve metadata such as file name, etc. Since those modules are in C, opening sockets and transmitting data is not a big deal.
The biggest caveat is probably that you need a complex compilation environment if you would like to target the Windows platform. Have a look at the compilation HOWTO's on the wiki http://wiki.videolan.org/Compile_VLC/ since this is probably what you would like to try prior to doing any coding.
Thinking about it, you can probably achieve a similarly featured extension in lua, which is easier to develop (since you don't need to compile VLC yourself and it will cross-platform). Opening UDP sockets might be problematic though. TCP will just work. This page could be a nice starting point: http://www.coderholic.com/extending-vlc-with-lua/