masmu / pulseaudio-dlna

A lightweight streaming server which brings DLNA / UPNP and Chromecast support to PulseAudio and Linux
GNU General Public License v3.0
1.25k stars 162 forks source link

XBox360 not working #108

Closed JarlJansen closed 8 years ago

JarlJansen commented 8 years ago

When I try to play liveaudio from linux via pulseaudio-dlna/pavucontrol I get error message from pulaseaudio-dlna like

10-16 23:15:52 pulseaudio_dlna.pulseaudio ERROR The device "Xbox 360 (DLNA)" failed to play! (500)

I have seen that XBox360 is not yet tested/supported. Will the XBox360 be supported by pulseaudio-dlna any time ?

masmu commented 8 years ago

There is no such thing as a list of devices I am planning to support. I try to do my best to make it work with every device I get my hands on. And that's somehow the problem. I do not own a Xbox 360 and therefore I need a lot of help from the people who is owning the device. That means typically: A process over some days to some weeks, where I:

But the XBox seems to be a good device for that. It is pretty popular. Wanna go on? The first thing I need is a full debug.log.

pulseaudio-dlna --debug 2>&1 | tee -a debug.log

Could you paste it somewhere and link it here?

JarlJansen commented 8 years ago

Let's go on. Here is the log:

http://pastebin.com/raw.php?i=Eg2zm0cE

According to the log the XBox360 is playing but there is no sound. After adjusting volume for the XBox360 via pavucontrol I get debug message "XBox is stopped.". What could be the reason for that ? Why do I get no sound while playing ?

Thx for your support :-)

JarlJansen commented 8 years ago

Sorry, I was wrong. XBox is really playing but it takes up to 45 seconds before playing starts. Is there any buffer that can be decreased to reduce this delay ? Changing to another song also takes up to 30 seconds And there is another issue: Sometimes without doing anything the XBox stops playing. From that moment this happens every 3 minutes. According to the log the XBox should still play at this moment. You need to restart playing to continue for another 3 minutes playing.

masmu commented 8 years ago

Thank you for testing this yourself a bit more. 45 seconds is quite a huge delay. There are two explanations possible. For the first one see the topic "There is a delay about a few seconds" in the readme. But in that case it is more likely that the second one is correct, because no buffer should take 45 seconds to fill. How is that device connected? Weak wifi, cable?

So, I can only assume that this is because of microsoft's implementation of detecting mp3 streams. A little more explanation: If you transcode an audio file via lame there is a mp3 header written to the new file after the transcoding finished. In that header you will find information about the used codec settings, information which must be detected by the device's decoder if those are missing. Since pulseaudio-dlna streams your live audio there is no such thing as and end and the lame encoder won't send the header at all. So, if you are using lame you are relying on a good and fast device decoder detection. There are some devices which can handle that really well and very fast. E.g. the D-Link DCH-M225/E which is using mplayer (awesome!) internally. Detection time: Nearly none. Then I've experienced devices which do take a little longer. E.g. all the Sonos ones. They need approximately 5 seconds for that. But 45 seconds is huge :wink:

As an alternative I could play with ffmpeg (can also produce mp3) as encoder. Perhaps it is writing the header at the beginning, never tested that.

There are other encoders which do write that header at the beginning, e.g. sox (wav, l16). So, to test that, I would recommend to use those codecs and see what happens.

pulseaudio-dlna --encoder wav
pulseaudio-dlna --encoder l16
JarlJansen commented 8 years ago

I got an error that wav is no suitable codec for the xbox. I16 works with delay of max 5 seconds and sometimes interruptions, but speed is too fast during playback. Maybe is has to do with this warning:

10-21 22:28:29 pulseaudio_dlna.streamserver INFO Processes of /dWRuPSJ1dWlkOjA4MTk5MDExLTM2MDUtMjAwMC0wMDAwLTdjZWQ4ZGY4OGYzNiI%3D/stream.pcm16 initialized ... sox WARN wav: Length in output .wav header will be wrong since can't seek to fix it

masmu commented 8 years ago

How is your device connected to you LAN? Cable or Wifi? If it is Wifi, how is the signal strength?

Your device claims to support the following codecs:

http-get:*:audio/mpeg:DLNA.ORG_PN=MP3
http-get:*:audio/mpeg:DLNA.ORG_PN=MP3X
http-get:*:audio/x-ms-wma:DLNA.ORG_PN=WMABASE
http-get:*:audio/x-ms-wma:DLNA.ORG_PN=WMAFULL
http-get:*:audio/x-ms-wma:DLNA.ORG_PN=WMALSL
http-get:*:audio/x-ms-wma:DLNA.ORG_PN=WMALSL_MULT5
http-get:*:audio/x-ms-wma:DLNA.ORG_PN=WMAPRO
http-get:*:audio/L16:DLNA.ORG_PN=LPCM
http-get:*:audio/L16;rate=44100;channels=1:DLNA.ORG_PN=LPCM
http-get:*:audio/L16;rate=44100;channels=2:DLNA.ORG_PN=LPCM
http-get:*:audio/L16;rate=48000;channels=1:DLNA.ORG_PN=LPCM
http-get:*:audio/L16;rate=48000;channels=2:DLNA.ORG_PN=LPCM
http-get:*:image/jpeg:DLNA.ORG_PN=JPEG_LRG
http-get:*:image/jpeg:DLNA.ORG_PN=JPEG_MED
http-get:*:image/jpeg:DLNA.ORG_PN=JPEG_SM
http-get:*:video/mpeg:DLNA.ORG_PN=MPEG_PS_NTSC
http-get:*:video/mpeg:DLNA.ORG_PN=MPEG_TS_SD_NA_ISO
http-get:*:video/mpeg:DLNA.ORG_PN=AVC_TS_MP_SD_AAC_MULT5_ISO
http-get:*:video/mpeg:DLNA.ORG_PN=AVC_TS_MP_HD_AAC_MULT5_ISO
http-get:*:video/vnd.dlna.mpeg-tts:DLNA.ORG_PN=MPEG_TS_SD_NA
http-get:*:video/vnd.dlna.mpeg-tts:DLNA.ORG_PN=MPEG_TS_SD_NA_T
http-get:*:video/x-ms-asf:DLNA.ORG_PN=VC1_ASF_AP_L1_WMA
http-get:*:video/x-ms-asf:DLNA.ORG_PN=VC1_ASF_AP_L2_WMA
http-get:*:video/x-ms-wmv:DLNA.ORG_PN=WMVHIGH_FULL
http-get:*:video/x-ms-wmv:DLNA.ORG_PN=WMVHIGH_PRO
http-get:*:video/x-ms-wmv:DLNA.ORG_PN=WMVMED_BASE
http-get:*:video/x-ms-wmv:DLNA.ORG_PN=WMVMED_FULL
http-get:*:video/x-ms-wmv:DLNA.ORG_PN=WMVMED_PRO
http-get:*:video/x-ms-wmv:DLNA.ORG_PN=WMVSPLL_BASE
http-get:*:video/x-ms-wmv:DLNA.ORG_PN=WMVSPML_BASE
http-get:*:audio/mp4:*
http-get:*:audio/mpeg:*
http-get:*:audio/x-ms-wma:*
http-get:*:audio/L16:*
http-get:*:image/jpeg:*
http-get:*:video/avi:*
http-get:*:video/mpeg:*
http-get:*:video/vnd.dlna.mpeg-tts:*
http-get:*:video/mp4:*
http-get:*:video/quicktime:*
http-get:*:video/x-ms-asf:*
http-get:*:video/x-ms-wmv:*
microsoft.com:*:application/vnd.ms-playtoapp;target="ms-playtoapp-xboxvideo":*
microsoft.com:*:application/vnd.ms-playtoapp;target="ms-playtoapp-xboxmusic":*

So, that wav does not work is because microsoft does not support it. But that is not that much a problem. l16 and wav are pretty similar.

Could you paste me another debug.log with the l16 encoder? And I need the output of

pactl list sink-inputs

while this is running.

JarlJansen commented 8 years ago

I have a Netbook conncted to my Wifi-Router via Wifi 150MBit/s, my Xbox360 is also connected via Wifi 72MBit/s . That should be far enough for streaming.

Here is debug.log for I16:

http://pastebin.com/raw.php?i=PJzqGvwx

Here is pactl output:

http://pastebin.com/raw.php?i=B4yN7n2D

The reason that speed is too fast is maybe that I16 encoder and Xbox are using different sample rates. As there is no header transferred to the Xbox, the XBox can not know proper sample rate. Fix might be 1.) transfer proper header to the XBox containing sample rate 2.) adjust sample rate for I16 encoder to the sample rate that is used by the XBox for playback.

What do you think ?

masmu commented 8 years ago

Thanks, the output of pactl is fine, but could you do a full debug.log like the last time?

pulseaudio-dlna --debug 2>&1 | tee -a debug.log
masmu commented 8 years ago

And I finally got an idea what is happening. Could you run pulseaudio-dlna --create-device-configone time? It will create a devices.json. Please paste it here, I change it here to a hopefully working example.

JarlJansen commented 8 years ago

Here you are:

debug.log

http://pastebin.com/raw.php?i=CdQviM5s

masmu commented 8 years ago

Thanks. I think pulseaudio-dlna selects the wrong sample rate or it is converted the wrong way. Could you provide the mentioned devices.json? It think we can make it work in 2 minutes ...

JarlJansen commented 8 years ago

Here is device config:

{ "uuid:08199011-3605-2000-0000-7ced8df88f36": { "rules": [], "flavour": "DLNA", "name": "Xbox 360", "codecs": [ { "rules": [], "bit_rate": null, "identifier": "mp3", "mime_type": "audio/mpeg" }, { "channels": 2, "rules": [], "identifier": "l16", "sample_rate": 48000, "mime_type": "audio/L16;rate=48000;channels=2" }, { "channels": 2, "rules": [], "identifier": "l16", "sample_rate": 44100, "mime_type": "audio/L16;rate=44100;channels=2" }, { "channels": 1, "rules": [], "identifier": "l16", "sample_rate": 48000, "mime_type": "audio/L16;rate=48000;channels=1" }, { "channels": 1, "rules": [], "identifier": "l16", "sample_rate": 44100, "mime_type": "audio/L16;rate=44100;channels=1" }, { "channels": null, "rules": [], "identifier": "l16", "sample_rate": null, "mime_type": "audio/L16" } ] } }

masmu commented 8 years ago

Ok, please replace your devices.json with the following:

{
    "uuid:08199011-3605-2000-0000-7ced8df88f36": {
        "rules": [], 
        "flavour": "DLNA", 
        "name": "Xbox 360", 
        "codecs": [
            {
                "channels": 2, 
                "rules": [], 
                "identifier": "l16", 
                "sample_rate": 44100, 
                "mime_type": "audio/L16;rate=44100;channels=2"
            }
        ]
    }
}
masmu commented 8 years ago

Then just start pulseaudio-dlna without specifying any flags. No --encoder and no --bit-rate flags at least ...

JarlJansen commented 8 years ago

Works fine :-) It's playing with proper speed without any interruptions.

Thx a lot for your support. Now pulseaudio-dlna is also XBox360 certified ;-)

masmu commented 8 years ago

We now know why the problem occurred. But other Xbox 360 users will still suffer from this. Can you help me to fix the problem for all? It will require you to install a local version of pulseaudio-dlna ...

JarlJansen commented 8 years ago

Sure. I can do this for you.

masmu commented 8 years ago

Ok, are you on Ubuntu and are you familiar with git?

JarlJansen commented 8 years ago

Not yet.

masmu commented 8 years ago

No problem. Glad that you help me to fix this for all :wink:

Please remove the created devices.json, so that the problem should reoccur.

# remove the ppa based pulseaudio-dlna version
sudo apt-get remove pulseaudio-dlna

# install all dependencies (if you installed the ppa version before this should not install anything new)
sudo apt-get install python2.7 python-pip python-setuptools python-dbus python-beautifulsoup python-docopt python-requests python-setproctitle python-gobject python-protobuf python-notify2 python-psutil python-concurrent.futures python-chardet vorbis-tools sox lame flac faac opus-tools

# install dependencies necessary for python virtual env
sudo apt-get install virtualenv python-dev git

# goto some folder, e.g. your home folder
cd ~

# clone the actual code and change to that directory
git clone https://github.com/masmu/pulseaudio-dlna.git
cd pulseaudio-dlna/

# checkout the branch
git checkout bug/xbox-360

# make the application runnable
make

# run it
bin/pulseaudio-dlna --encoder l16

I am currently working on the fix...

JarlJansen commented 8 years ago

done

JarlJansen commented 8 years ago

Is this version already including the bug-fix ?

masmu commented 8 years ago

Thank you! No, I am still working on it... I am not quite sure if there is a bug in microsofts l16 implementation or I am doing this wrong. I guess i am doing it wrong :smile:

JarlJansen commented 8 years ago

I removed my encoders together with pulseaudio-dlna. How to reinstall I16 on Ubuntu ?

masmu commented 8 years ago
sudo apt-get install python2.7 python-pip python-setuptools python-dbus python-beautifulsoup python-docopt python-requests python-setproctitle python-gobject python-protobuf python-notify2 python-psutil python-concurrent.futures python-chardet vorbis-tools sox lame flac faac opus-tools

sox is the wav and l16 encoder. So it should be enought

sudo apt-get install sox
masmu commented 8 years ago

sox is the l16 encoder. If you startup pulseaudio-dlna there will be a line for the l16 encoder within the encoder settings. Like:

10-24 13:09:13 pulseaudio_dlna.application                    INFO     Encoder settings:
10-24 13:09:13 pulseaudio_dlna.application                    INFO       <AacEncoder available="True" bit-rate="192">
10-24 13:09:13 pulseaudio_dlna.application                    INFO       <FlacEncoder available="False">
10-24 13:09:13 pulseaudio_dlna.application                    INFO       <L16Encoder available="True" sample-rate="44100" channels="2">

If it is listed as available="True" everything is ok. E.g. you can see that i did not install the flac encoder as it is listed as available="False".

JarlJansen commented 8 years ago

Sorry, my mistake. It's L16 encoder, not I16 ;-) Tried to start with "--encoder I16" instead of "--encoder l16" ;-)

JarlJansen commented 8 years ago

Now it's like before using L16 encoder. Speed too fast, interruptions every 3 minutes.

masmu commented 8 years ago

Hmm, Ok. I placed some additional logs in the branch. Please shutdown pulseaudio-dlna, do a git pull (will recieve my changes) restart it and please paste the output of it here. I assume it is still too fast?

JarlJansen commented 8 years ago

Think i should do another "make" before restart, right ?

masmu commented 8 years ago

Nope, this is required only once to make the application runnable.

JarlJansen commented 8 years ago

Sorry, still too fast.

http://pastebin.com/raw.php?i=rp2RVJbc

masmu commented 8 years ago

Ok, i resorted the sample rates. Please shutdown pulseaudio-dlna, do a git pull and restart it.

JarlJansen commented 8 years ago

Now as i am used to faster speed i would say "too slow" ;-)

No, just a joke ! Works perfect !!! But i am still using "--encoder l16". Do I still need that ?

masmu commented 8 years ago

Glad to hear!

You can use the devices.json which selects the encoder for you. I recommend to delete the folder we just created with the virtualenv. After that just install pulseaudio-dlna via apt-get again and restore the devices.json. That reverts all changes. After that it should be as it was before we did some of the testing. You can then just start it via pulseaudio-dlna ...

Just for your information: A HTTP header informes your Xbox that the following data will be encoded with a specific sample rate. In your case pulseaudio-dlna choosed 48khz because it was the highest settings available. The xbox (i assume) did not recognize that header and played it with 44.1khz and therefore it was faster then expected. Normally it should do as requested and play it with 48khz (as instructed through that HEADER) which would result in normal play speed. But somehow it ignores that. So, my fix for that problem is to always prefer 44.1khz audio data, since the source data is encoded with that sample rate and there is no benefit in using a higher sample rate if the source quality is below that.

masmu commented 8 years ago