petro-kushchak / homebridge-homepod-radio

MIT License
36 stars 2 forks source link

way to increase the buffer size?! #6

Open drpodmeer opened 2 years ago

drpodmeer commented 2 years ago

Hi, you have made a great progress in the last weeks, thanks for that.

Do you think it would be possible to increase the streaming buffer size, my homebridge is connected to wifi and I often have interruptions in the sound and audio artifacts. especially with this radio. http://grrif.ice.infomaniak.ch/grrif-high.mp3

and the Radio is turning off after certain minutes.

Thanks and have a good time

petro-kushchak commented 2 years ago

Hi,

I tried to play with radio url you gave and there were no issues on my side (maybe because I run Raspberry Pi 4 Model B Rev 1.4 with 4Gb RAM? or better connectivity to that radio from my location...)

Also looks like ffmpeg allows to set some "Real-time buffer" so I published build 1.1.20-alpha which sets that buffer to 15Mb (default is 3Mb)... Could you try it out?

drpodmeer commented 2 years ago

hi petro, its not working anymore, i got following error: 8D2BF28A-B1A5-481C-BEC7-F370AD717161

i can spend thursday a bit more time. have a nice day

samsonrosen commented 2 years ago

Might not be the same but I had something like this with these errors after I changed my config and updated to the alpha update. I discovered I also couldn’t use the ffmpeg | pyatv command that is referenced in the readme due to an internal error with pyatv. To resolve I:

  1. Toggled they security/who can access on the HomePod
  2. Rebooted the HomePod
  3. Rebooted the server with homebridge on it

Now I’d argue it’s working better than before for speed with the new cache update.

petro-kushchak commented 2 years ago

@samsonrosen - I've also noticed that sometimes (maybe once or twice) HomePod mini starts returning errors, looks like streaming from external apps is not fully polished yet and that might be one of the reasons why Apple still does not allow this for any app... In my case rebooting HomePod mini helped

@drpodmeer - could you please enable debug mode (verboseMode: true in plugin config) with your test?

drpodmeer commented 2 years ago

Hi Petro

After rebooting the HomePod, the plug-in works

Increasing the buffer has helped a little.

every time there is an acoustic disturbance, the following message appears:

[23/01/2022, 09:41:19] [HomepodRadioPlatform] [BBC1] ffmpeg pipe error: Error: write EPIPE

and Homebridge crashes completely on the RP3. I have to pull the plug to restart.

complete log: (before crash)

[23/01/2022, 09:37:45] [HomepodRadioPlatform] [BBC1] Setting volume to 35 [23/01/2022, 09:37:46] [HomepodRadioPlatform] [BBC1] Started streaming http://stream.live.vc.bbcmedia.co.uk/bbc_radio_one [23/01/2022, 09:37:46] [HomepodRadioPlatform] [BBC1] Setting volume to 35 [23/01/2022, 09:38:00] [HomepodRadioPlatform] [BBC1] ffmpeg pipe error: Error: write EPIPE [23/01/2022, 09:38:58] [HomepodRadioPlatform] [BBC1] Triggered GET CurrentMediaState: 0 [23/01/2022, 09:38:58] [HomepodRadioPlatform] [Radio Grrif] Triggered GET CurrentMediaState: 2 [23/01/2022, 09:38:59] [HomepodRadioPlatform] [BBC1] Triggered GET CurrentMediaState: 0 [23/01/2022, 09:38:59] [HomepodRadioPlatform] [Radio Grrif] Triggered GET CurrentMediaState: 2 [23/01/2022, 09:39:45] [HomepodRadioPlatform] [BBC1] Restarting playback... total attempts: 0 [23/01/2022, 09:39:46] [HomepodRadioPlatform] [BBC1] Started streaming http://stream.live.vc.bbcmedia.co.uk/bbc_radio_one [23/01/2022, 09:39:46] [HomepodRadioPlatform] [BBC1] Setting volume to 35 [23/01/2022, 09:39:46] [HomepodRadioPlatform] [BBC1] Restarting playback... total attempts: 0 [23/01/2022, 09:39:47] [HomepodRadioPlatform] [BBC1] Started streaming http://stream.live.vc.bbcmedia.co.uk/bbc_radio_one [23/01/2022, 09:39:47] [HomepodRadioPlatform] [BBC1] Setting volume to 35 [23/01/2022, 09:40:03] [HomepodRadioPlatform] [BBC1] ffmpeg pipe error: Error: write EPIPE [23/01/2022, 09:40:57] [HomepodRadioPlatform] [BBC1] Restarting playback... total attempts: 0 [23/01/2022, 09:40:58] [HomepodRadioPlatform] [BBC1] Restarting playback... total attempts: 0 [23/01/2022, 09:40:58] [HomepodRadioPlatform] [BBC1] Started streaming http://stream.live.vc.bbcmedia.co.uk/bbc_radio_one [23/01/2022, 09:40:58] [HomepodRadioPlatform] [BBC1] Setting volume to 35 [23/01/2022, 09:40:58] [HomepodRadioPlatform] [BBC1] Started streaming http://stream.live.vc.bbcmedia.co.uk/bbc_radio_one [23/01/2022, 09:40:58] [HomepodRadioPlatform] [BBC1] Setting volume to 35 [23/01/2022, 09:40:58] [HomepodRadioPlatform] [BBC1] Restarting playback... total attempts: 0 [23/01/2022, 09:40:59] [HomepodRadioPlatform] [BBC1] Started streaming http://stream.live.vc.bbcmedia.co.uk/bbc_radio_one [23/01/2022, 09:40:59] [HomepodRadioPlatform] [BBC1] Setting volume to 35 [23/01/2022, 09:40:59] [HomepodRadioPlatform] [BBC1] Restarting playback... total attempts: 0 [23/01/2022, 09:41:00] [HomepodRadioPlatform] [BBC1] Started streaming http://stream.live.vc.bbcmedia.co.uk/bbc_radio_one [23/01/2022, 09:41:00] [HomepodRadioPlatform] [BBC1] Setting volume to 35 [23/01/2022, 09:41:17] [HomepodRadioPlatform] [BBC1] ffmpeg pipe error: Error: write EPIPE [23/01/2022, 09:41:18] [HomepodRadioPlatform] [BBC1] ffmpeg pipe error: Error: write EPIPE [23/01/2022, 09:41:19] [HomepodRadioPlatform] [BBC1] ffmpeg pipe error: Error: write EPIPE [23/01/2022, 09:42:08] [HomepodRadioPlatform] [BBC1] Restarting playback... total attempts: 0 [23/01/2022, 09:42:09] [HomepodRadioPlatform] [BBC1] Started streaming http://stream.live.vc.bbcmedia.co.uk/bbc_radio_one [23/01/2022, 09:42:09] [HomepodRadioPlatform] [BBC1] Setting volume to 35 [23/01/2022, 09:42:10] [HomepodRadioPlatform] [BBC1] Restarting playback... total attempts: 0 [23/01/2022, 09:42:11] [HomepodRadioPlatform] [BBC1] Started streaming http://stream.live.vc.bbcmedia.co.uk/bbc_radio_one [23/01/2022, 09:42:11] [HomepodRadioPlatform] [BBC1] Setting volume to 35 [23/01/2022, 09:42:11] [HomepodRadioPlatform] [BBC1] Restarting playback... total attempts: 0 [23/01/2022, 09:42:11] [HomepodRadioPlatform] [BBC1] Started streaming http://stream.live.vc.bbcmedia.co.uk/bbc_radio_one [23/01/2022, 09:42:11] [HomepodRadioPlatform] [BBC1] Setting volume to 35 [23/01/2022, 09:42:12] [HomepodRadioPlatform] [BBC1] Restarting playback... total attempts: 0 [23/01/2022, 09:42:12] [HomepodRadioPlatform] [BBC1] Started streaming http://stream.live.vc.bbcmedia.co.uk/bbc_radio_one [23/01/2022, 09:42:12] [HomepodRadioPlatform] [BBC1] Setting volume to 35

petro-kushchak commented 2 years ago

Hi, I've noticed yesterday that sometimes when plugin tries to restart streaming ffmpeg&atvremote are not killed properly and after 4-6 hours or playing (depends how often original radio stream gets interrupted) my Pi runs out of memory (so Homebridge process starts crashing). I pushed some tweak and testing them with build version v1.1.35-beta.3

ccrismancox commented 2 years ago

I am also having the problem described by @drpodmeer

[2/25/2022, 11:55:14 AM] [HomepodRadioPlatform] [NPR Downstairs] Triggered GET CurrentMediaState: 2
[2/25/2022, 11:55:14 AM] [HomepodRadioPlatform] [NPR Downstairs] Triggered SET TargetMediaState: 0
[2/25/2022, 11:55:14 AM] [HomepodRadioPlatform] [NPR Downstairs] Started hearbeat 2274
[2/25/2022, 11:55:14 AM] [HomepodRadioPlatform] [NPR Downstairs] Started streaming https://stream.houstonpublicmedia.org/news-aac
[2/25/2022, 11:55:14 AM] [HomepodRadioPlatform] [NPR Downstairs] Setting volume to 75
[2/25/2022, 11:55:20 AM] [HomepodRadioPlatform] [NPR Downstairs] Restarting playback... total attempts: 0
[2/25/2022, 11:55:20 AM] [HomepodRadioPlatform] [NPR Downstairs] Cleared hearbeat 2274 - previous timer
[2/25/2022, 11:55:20 AM] [HomepodRadioPlatform] [NPR Downstairs] Started hearbeat 3131
[2/25/2022, 11:55:20 AM] [HomepodRadioPlatform] [NPR Downstairs] Started streaming https://stream.houstonpublicmedia.org/news-aac
[2/25/2022, 11:55:20 AM] [HomepodRadioPlatform] [NPR Downstairs] Setting volume to 75
[2/25/2022, 11:55:26 AM] [HomepodRadioPlatform] [NPR Downstairs] ffmpeg pipe error: Error: write EPIPE
[2/25/2022, 11:55:26 AM] [HomepodRadioPlatform] [NPR Downstairs] Restarting playback... total attempts: 0
[2/25/2022, 11:55:27 AM] [HomepodRadioPlatform] [NPR Downstairs] Cleared hearbeat 3131 - previous timer
[2/25/2022, 11:55:27 AM] [HomepodRadioPlatform] [NPR Downstairs] Started hearbeat 4162
[2/25/2022, 11:55:27 AM] [HomepodRadioPlatform] [NPR Downstairs] Started streaming https://stream.houstonpublicmedia.org/news-aac
[2/25/2022, 11:55:27 AM] [HomepodRadioPlatform] [NPR Downstairs] Setting volume to 75
[2/25/2022, 11:55:33 AM] [HomepodRadioPlatform] [NPR Downstairs] ffmpeg pipe error: Error: write EPIPE

When I run it from the command line ffmpeg -i https://stream.houstonpublicmedia.org/news-aac -f mp3 - | atvremote --id <homepodid> stream_file=- it works perfectly with no issue, but once I run it through the homebridge I get the EPIPE errors and constant restarts

ccrismancox commented 2 years ago

At least in my case it's not the buffer size. I raised HEARTBEAT_TIMEOUT and LAST_SEEN_THRESHOLD_MS both to 10000 and that solved the problem. As I understand it the stream was just refreshing faster than the original values could handle. Both variables are in the file src/lib/airPlayDevice.ts. It might be nice to be able to set these in the config file