From 7a2ba572f871aa8b0228b25e164e714a3fced096 Mon Sep 17 00:00:00 2001 From: chme Date: Thu, 14 Feb 2019 12:15:11 +0100 Subject: [PATCH 1/9] [streaming] Remove timeout for mpeg stream requests Remove the need for clients to regularly reconnect to the mp3 stream. As long as the connection is open, we are sending mp3 stream data. --- src/httpd_streaming.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/httpd_streaming.c b/src/httpd_streaming.c index 52b6bfdb..547b624d 100644 --- a/src/httpd_streaming.c +++ b/src/httpd_streaming.c @@ -46,8 +46,6 @@ extern struct event_base *evbase_httpd; #define STREAMING_SILENCE_INTERVAL 1 // Buffer size for transmitting from player to httpd thread #define STREAMING_RAWBUF_SIZE (STOB(AIRTUNES_V2_PACKET_SAMPLES)) -// Should prevent that we keep transcoding to dead connections -#define STREAMING_CONNECTION_TIMEOUT 60 // Linked list of mp3 streaming requests struct streaming_session { @@ -74,6 +72,7 @@ static struct player_status streaming_player_status; static int streaming_player_changed; static int streaming_pipe[2]; + static void streaming_fail_cb(struct evhttp_connection *evcon, void *arg) { @@ -243,6 +242,8 @@ streaming_request(struct evhttp_request *req, struct httpd_uri_parsed *uri_parse evhttp_add_header(output_headers, "Pragma", "no-cache"); evhttp_add_header(output_headers, "Expires", "Mon, 31 Aug 2015 06:00:00 GMT"); evhttp_add_header(output_headers, "icy-name", name); + evhttp_add_header(output_headers, "Access-Control-Allow-Origin", "*"); + evhttp_add_header(output_headers, "Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS"); // TODO ICY metaint evhttp_send_reply_start(req, HTTP_OK, "OK"); @@ -263,7 +264,6 @@ streaming_request(struct evhttp_request *req, struct httpd_uri_parsed *uri_parse session->next = streaming_sessions; streaming_sessions = session; - evhttp_connection_set_timeout(evcon, STREAMING_CONNECTION_TIMEOUT); evhttp_connection_set_closecb(evcon, streaming_fail_cb, session); return 0; From 3b718ffb16f2d3903efe38228e6c3959e5a4f7b5 Mon Sep 17 00:00:00 2001 From: chme Date: Thu, 14 Feb 2019 12:19:29 +0100 Subject: [PATCH 2/9] [web-src] Add option to stream audio from player web interface The audio implementation is based on https://github.com/rainner/soma-fm-player and makes use of the HTML5 Web Audio Context API. --- web-src/src/audio.js | 51 +++++++++++ web-src/src/components/NavBarItemOutput.vue | 2 +- web-src/src/components/NavbarTop.vue | 97 ++++++++++++++++++++- web-src/vue.config.js | 7 +- 4 files changed, 153 insertions(+), 4 deletions(-) create mode 100644 web-src/src/audio.js diff --git a/web-src/src/audio.js b/web-src/src/audio.js new file mode 100644 index 00000000..00363256 --- /dev/null +++ b/web-src/src/audio.js @@ -0,0 +1,51 @@ +/** + * Audio handler object + * Taken from https://github.com/rainner/soma-fm-player (released under MIT licence) + */ +export default { + _audio: new Audio(), + _context: new AudioContext(), + _source: null, + _gain: null, + _analyser: null, + + // setup audio routing + setupAudio () { + this._source = this._context.createMediaElementSource(this._audio) + this._analyser = this._context.createAnalyser() + this._gain = this._context.createGain() + + this._source.connect(this._gain) + this._source.connect(this._analyser) + this._gain.connect(this._context.destination) + + this._audio.addEventListener('canplaythrough', e => { + this._audio.play() + }) + return this._audio + }, + + // set audio volume + setVolume (volume) { + if (!this._gain) return + volume = parseFloat(volume) || 0.0 + volume = (volume < 0) ? 0 : volume + volume = (volume > 1) ? 1 : volume + this._gain.gain.value = volume + }, + + // play audio source url + playSource (source) { + this.stopAudio() + this._audio.src = String(source || '') + '?x=' + Date.now() + this._audio.crossOrigin = 'anonymous' + this._audio.load() + }, + + // stop playing audio + stopAudio () { + try { this._audio.pause() } catch (e) {} + try { this._audio.stop() } catch (e) {} + try { this._audio.close() } catch (e) {} + } +} diff --git a/web-src/src/components/NavBarItemOutput.vue b/web-src/src/components/NavBarItemOutput.vue index 881ec6c8..53d67957 100644 --- a/web-src/src/components/NavBarItemOutput.vue +++ b/web-src/src/components/NavBarItemOutput.vue @@ -3,7 +3,7 @@
- +
diff --git a/web-src/src/components/NavbarTop.vue b/web-src/src/components/NavbarTop.vue index 84c5802b..80b30e70 100644 --- a/web-src/src/components/NavbarTop.vue +++ b/web-src/src/components/NavbarTop.vue @@ -60,6 +60,31 @@ + + +