owntone / owntone-server

Linux/FreeBSD DAAP (iTunes) and MPD audio server with support for AirPlay 1 and 2 speakers (multiroom), Apple Remote (and compatibles), Chromecast, Spotify and internet radio.
https://owntone.github.io/owntone-server
GNU General Public License v2.0
2.1k stars 237 forks source link

Enhancement add pcm network stream #971

Open frankusb opened 4 years ago

frankusb commented 4 years ago

In addition to http://[your hostname/ip address]:3689/stream.mp3 would it be possible to add http://[your hostname/ip address]:3689/stream.pcm to play lossless audio?

whatdoineed2do commented 4 years ago

This isn't too difficult to do/all in one module and mostly relocating globals into per-streamable contexts.

I've got a working prototype of this that will easily allow us to extend the supported streamable formats current supporting: mp3, 44.1k wav and 48k wav in my dev branch. I've got to run in head through the thread interactions for player event changes given the potential multiple clients per streamable format but hopefully that won't take too long.

After that, @frankusb can I ask you to help test it?

frankusb commented 4 years ago

Absolutely I will help test it.

On Fri, May 1, 2020 at 5:26 AM whatdoineed2do notifications@github.com wrote:

This isn't too difficult to do/all in one module and mostly relocating globals into per-streamable contexts.

I've got a working prototype of this that will easily allow us to extend the supported streamable formats current supporting: mp3, 44.1k wav and 48k wav in my dev branch. I've got to run in head through the thread interactions for player event changes given the potential multiple clients per streamable format but hopefully that won't take too long.

After that, @frankusb https://github.com/frankusb can I ask you to help test it?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ejurgensen/forked-daapd/issues/971#issuecomment-622333624, or unsubscribe https://github.com/notifications/unsubscribe-auth/APETTJVJQAUPJNZXQJT2YCLRPKPURANCNFSM4MTCAPIQ .

whatdoineed2do commented 4 years ago

@frankusb - I have this functionality completed - it obviously pending proper review (and hence changes/new bugs introduced/fixed) but it works as intended.

The branch with update is here: https://github.com/whatdoineed2do/forked-daapd/tree/streaming-multiformat and all within httpd_streaming.c. Connect to http://your_forked_ server:3689/stream.pcm (or stream48k.pcm if you want the 48k encoded stream).

There should be no constant glitching in the audio stream. It would be good to see how this works with streaming to multiple clients and the responsiveness of the forked-daapd process (browsing/adding tracks using the web or phone/tablet app).

Obviously the PCM 44.1/48 stream is going to be more data over the network and I'd be interested how it plays out in real life (over wifi over slow lan etc) since I've done limited testing sending to my wired 100mbit Soundbridge and mostly tested on localhost - I assume your Soundbridge is one endpoint you're trying to get wiorking.

frankusb commented 4 years ago

I've got 2 48k Soundbridges on wireless and two 44.1k wired that I will test with.

frankusb commented 4 years ago

I tried with an M1001 and an M500. Log from M500 below.

http://192.168.1.52:3689/stream.pcm is not working for me.

[2020-05-01 14:36:59] [DEBUG] player: Player status: playing [2020-05-01 14:37:22] [ INFO] stream: Beginning PCM16 44.1 streaming (with icy=1, icy_metaint=16384) to ::ffff:192.168.1.45:33001 [2020-05-01 14:37:22] [DEBUG] ffmpeg: tb:1/44100 samplefmt:s16 samplerate:44100 chlayout:0x3 [2020-05-01 14:37:22] [DEBUG] xcode: Created 'in' filter: time_base=1/44100:sample_rate=44100:sample_fmt=s16:channel_layout=0x3 [2020-05-01 14:37:22] [DEBUG] xcode: Created 'format' filter: sample_fmts=s16:sample_rates=44100:channel_layouts=0x3 [2020-05-01 14:37:22] [ INFO] stream: Stopping PCM16 44.1 streaming to ::ffff:192.168.1.45:33001 [2020-05-01 14:37:22] [ INFO] stream: No more clients, will stop streaming PCM16 44.1

http://192.168.1.52:3689/stream48k.pcm is not working for me.

[2020-05-01 14:39:26] [ INFO] stream: Beginning PCM16 48 streaming (with icy=1, icy_metaint=16384) to ::ffff:192.168.1.45:33006 [2020-05-01 14:39:26] [DEBUG] ffmpeg: tb:1/44100 samplefmt:s16 samplerate:44100 chlayout:0x3 [2020-05-01 14:39:26] [DEBUG] xcode: Created 'in' filter: time_base=1/44100:sample_rate=44100:sample_fmt=s16:channel_layout=0x3 [2020-05-01 14:39:26] [DEBUG] xcode: Created 'format' filter: sample_fmts=s16:sample_rates=48000:channel_layouts=0x3 [2020-05-01 14:39:26] [DEBUG] ffmpeg: auto-inserting filter 'auto_resampler_0' between the filter 'in' and the filter 'format' [2020-05-01 14:39:26] [DEBUG] ffmpeg: ch:2 chl:stereo fmt:s16 r:44100Hz -> ch:2 chl:stereo fmt:s16 r:48000Hz [2020-05-01 14:39:27] [ INFO] stream: Stopping PCM16 48 streaming to ::ffff:192.168.1.45:33006 [2020-05-01 14:39:27] [ INFO] stream: No more clients, will stop streaming PCM16 48 [2020-05-01 14:39:27] [ INFO] stream: Beginning PCM16 48 streaming (with icy=1, icy_metaint=16384) to ::ffff:192.168.1.45:33007 [2020-05-01 14:39:30] [ INFO] stream: Stopping PCM16 48 streaming to ::ffff:192.168.1.45:33007 [2020-05-01 14:39:30] [ INFO] stream: No more clients, will stop streaming PCM16 48

frankusb commented 4 years ago

I did verify http://192.168.1.52:3689/stream.pcm worked with VLC on Mac.

whatdoineed2do commented 4 years ago

Yes, the .pcm worked with mpv and ffmpeg streaming so the audio stream is valid.

Can you try this branch: https://github.com/whatdoineed2do/forked-daapd/tree/streaming-multiformat1

and connect to http://your_forked_ server:3689/stream.wav (or stream48k.wav). These are the same as the stream.pcm except ICY is not sent even if requested. I wonder is that the Soundbridge doesn't like these PCM streams with embedded ICY even though it asks for it.

frankusb commented 4 years ago

No that did not seem to work. The M500 acted differently, it retried quicker.

[2020-05-01 17:18:36] [ INFO] stream: Beginning PCM16 44.1 (no ICY) streaming (icy disabled) to ::ffff:192.168.1.45:36845 [2020-05-01 17:18:36] [DEBUG] ffmpeg: tb:1/44100 samplefmt:s16 samplerate:44100 chlayout:0x3 [2020-05-01 17:18:36] [DEBUG] xcode: Created 'in' filter: time_base=1/44100:sample_rate=44100:sample_fmt=s16:channel_layout=0x3 [2020-05-01 17:18:36] [DEBUG] xcode: Created 'format' filter: sample_fmts=s16:sample_rates=44100:channel_layouts=0x3 [2020-05-01 17:18:36] [ INFO] stream: Stopping PCM16 44.1 (no ICY) streaming to ::ffff:192.168.1.45:36845 [2020-05-01 17:18:36] [ INFO] stream: No more clients, will stop streaming PCM16 44.1 (no ICY) [2020-05-01 17:18:37] [ INFO] stream: Beginning PCM16 44.1 (no ICY) streaming (icy disabled) to ::ffff:192.168.1.45:36846 [2020-05-01 17:18:37] [ INFO] stream: Stopping PCM16 44.1 (no ICY) streaming to ::ffff:192.168.1.45:36846 [2020-05-01 17:18:37] [ INFO] stream: No more clients, will stop streaming PCM16 44.1 (no ICY)

whatdoineed2do commented 4 years ago

Not the best news for lossless streams to your Soundbridge - I think the problem may be related to the supported Roku streaming formats

The following HTTP-streamed formats are currently supported:

  • MP3 streams (usually ending in .pls or .m3u)
  • WMA streams (usually ending in .asx). You will need the 2.5 software installed on the SoundBridge to play these back.

There is preliminary support for the following stream format on most SoundBridge models:

  • AAC+ streams

Whilst the Soundbridge supports .wav files over DAAP (reconfirmed on my Pinnacle rebranded m500), it would appear it does not suppport .wav over http streaming.

The AAC+ (I think this became AAC HE) is an (lossy) encoding format not currently supported in the transcode module and I haven't quite figured out how to get this into the right ffmpeg params/options to make this work and maybe outside the scope of the main PR (add PCM streaming).

Nevertheless, I've committed to the alternative dev branch these WIP changes that you can play around with to see if you can get ffmpeg encoding to work.

frankusb commented 4 years ago

Hmm, I did find https://github.com/tsibley/soundbridge-utils which appears to imply soundbridge-upnp-play speakers is wav. But that could be not streaming.

In any case, I can increase the bitrate of mp3 streaming from 192k to 320k.

frankusb commented 4 years ago

I wonder if WMA streams include WMA lossless.

frankusb commented 4 years ago

Another note, https://github.com/tsibley/soundbridge-utils uses format=s16be. I noticed that init_settings uses settings->format = "s16le";.