Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Icecast ogg/flac output keeps disconnecting when using SRT input [2.2.0 nightly] #2965

Closed
rmens opened this issue Mar 19, 2023 · 9 comments · Fixed by #3062
Closed

Icecast ogg/flac output keeps disconnecting when using SRT input [2.2.0 nightly] #2965

rmens opened this issue Mar 19, 2023 · 9 comments · Fixed by #3062

Comments

@rmens
Copy link

rmens commented Mar 19, 2023

Describe the bug
I'm testing out replacing a Harbor input with a SRT input. Everything seems to work well, except that one of my three Icecast outputs disconnects when killing the SRT input and falling back to an audio file. There are three outputs to Icecast: output.icecast(%ogg(%flac), output.icecast(%mp3(bitrate=192,samplerate=48000) and output.icecast(%fdkaac(channels=2, samplerate=48000, bitrate=96, afterburner=true, aot='mpeg4_aac_lc', transmux='adts', sbr_mode=true). Only the ogg/flac output disconnects when switching from the SRT input to a static file.

In the logs there is an entry Error while sending data: could not write data to host: Unix.Unix_error(Unix.EPIPE, "write", "")!

This happens when transitioning from the SRT source to the fallback source. Not when transitioning from the fallback source to the SRT source.

To Reproduce
The script that I run is found here.

Expected behavior
All streams to Icecast to stay connected.

Version details

  • OS: Ubuntu 22.04
  • Version a7eea64_2.2.0

Install method
Nightly .deb package

root@liq220:/var/log/liquidsoap# tail -f radio.log 
2023/03/19 15:23:29 [ZW_FM:3] Connection setup was successful.
2023/03/19 15:25:44 [decoder:2] Decoding "/var/audio/fallback.ogg" ended: Ffmpeg_decoder.End_of_file.
2023/03/19 15:25:45 [single_0:3] Prepared "/var/audio/fallback.ogg" (RID 0).
2023/03/19 15:28:28 [decoder:2] Decoding "/var/audio/fallback.ogg" ended: Ffmpeg_decoder.End_of_file.
2023/03/19 15:28:28 [single_0:3] Prepared "/var/audio/fallback.ogg" (RID 0).
2023/03/19 15:31:05 [clock.input.srt:3] Delegating synchronisation to active sources
2023/03/19 15:31:05 [mksafe:3] Switch to studio with transition.
2023/03/19 15:31:05 [replay_metadata_16:3] Content type is {audio=pcm(stereo)}.
2023/03/19 15:31:06 [switch_1:3] Switch to blank.strip_0 with transition.
2023/03/19 15:31:06 [replay_metadata_17:3] Content type is {audio=pcm(stereo)}.
2023/03/19 15:31:36 [stderr:3] Error while executing OCaml read callback: Srt.Error(443488021, "Connection was broken")
2023/03/19 15:31:36 [studio:2] Feeding failed: Avutil.Error(Generic error in an external library)
2023/03/19 15:31:36 [mksafe:3] Switch to safe_blank with forgetful transition.
2023/03/19 15:31:36 [clock.input.srt:3] Delegating synchronisation to CPU clock
2023/03/19 15:31:49 [mksafe:3] Switch to studio with transition.
2023/03/19 15:31:49 [replay_metadata_18:3] Content type is {audio=pcm(stereo)}.
2023/03/19 15:31:49 [clock.input.srt:3] Delegating synchronisation to active sources
2023/03/19 15:31:49 [ZW_FM:2] Error while sending data: could not write data to host: Unix.Unix_error(Unix.EPIPE, "write", "")!
2023/03/19 15:31:49 [ZW_FM:3] Closing connection...
2023/03/19 15:31:49 [ZW_FM:3] Will try to reconnect in 3.00 seconds.
2023/03/19 15:31:53 [ZW_FM:3] Connecting mount /ZWFM.stl for source@localhost...
2023/03/19 15:31:53 [ZW_FM:3] Connection setup was successful.

The fallback file is https://upload.wikimedia.org/wikipedia/commons/6/66/Aaron_Dunn_-_Sonata_No_1_-_Movement_2.ogg

@rmens rmens changed the title Icecast ogg/flac output keeps disconnecting when using SRT input Icecast ogg/flac output keeps disconnecting when using SRT input [2.2.0 nightly] Mar 19, 2023
@toots
Copy link
Member

toots commented Mar 29, 2023

Hi @rmens thanks for reporting. I am looking into this and will get back to you shortly.

@toots
Copy link
Member

toots commented Mar 30, 2023

So looking at the script is seems that input.srt disconnections can potentially create some latency that would be propagated to output.icecast. Because flac has larger chunks of data, it's possible that it is the only one impacted because e.g. a long write gets interrupted while shorter writes get buffered and cause less friction?

At any rate, I would suggest to add a buffer to create separate clocks. Since all the icecast output go to the same server, I think the most sensible way to do it would be to add a buffer around the input.srt:

# Input for the studio stream
studio = input.srt(id="studio", port=9000, mode="listener", max=2.0, streamid="studio", passphrase=upstreampassword)

# Wrap it in a buffer to prevent latency from connection/disconnection to impact downstream operators/output
studio = buffer(fallible=true, studio)

@toots
Copy link
Member

toots commented Mar 30, 2023

As a side note, I'm curious to know if this is working or how you are making it work:

# Output configuration
output_config = (
  fallible=true,
  host=icecastserver,
  port=icecastport,
  password=icecastpassword,
  name='ZuidWest FM',
  radio
)

# Output a lossless ogg/flac stream
output.icecast(%ogg(%flac), description='Studio to Transmitter (ongecomprimeerde audio)', mount='/zuidwest.stl', output_config)

@rmens
Copy link
Author

rmens commented Mar 30, 2023

So looking at the script is seems that input.srt disconnections can potentially create some latency that would be propagated to output.icecast. Because flac has larger chunks of data, it's possible that it is the only one impacted because e.g. a long write gets interrupted while shorter writes get buffered and cause less friction?

Thanks @toots I'll check out if wrapping it in a buffer fixes it.

As a side note, I'm curious to know if this is working or how you are making it work:

This was an optimalisation ChatGPT suggested and I just copy/pasted 🙈 This doesn't seem to work however.

@rmens
Copy link
Author

rmens commented Mar 30, 2023

Did some more experimenting. Adding a buffer didn't solve the problem. However commenting the out the mksafe did the trick.

# Input for the studio stream
studio = input.srt(id="studio", port=9000, mode="listener", max=2.0, streamid="studio", passphrase=upstreampassword)

# Insert silence when there is no data from input
# studio = mksafe(studio) # This causes the ogg/flac stream to disconnect when switching between fallback and studio

# Wrap it in a buffer to prevent latency from connection/disconnection to impact downstream operators/output
studio = buffer(fallible=true, studio)

This doesn't seem to be a problem with SRT at all. I added the harbor input back as test and the behavior is the same. Sorry for the confusion. I can't really grasp why this is happening.

@rmens
Copy link
Author

rmens commented Mar 30, 2023

Booted up Liquidsoap 2.1.4 and the behavior is the same. This wasn't a 2.2.0 problem after all. This whole report is probably invalid.

@toots
Copy link
Member

toots commented May 5, 2023

Okay. Have you tried testing the ffmpeg encoder in case the issue is coming from our internal ogg/flac encoder? Something like this:

%ffmpeg(
  format="ogg",
  %audio(codec="flac")
)

@rmens
Copy link
Author

rmens commented May 6, 2023

Ok this is with

# Output a high quality ogg/flac stream
output.icecast(%ogg(%flac),fallible=true,
  host=icecastserver, port=icecastport, password=icecastpassword, mount='/zuidwest.stl', name='ZuidWest FM', description='Studio to Transmitter (uncompressed audio)', radio)

The "Error while sending data" occurs and the ogg/flac streams gets disconnected while switching.

2023/05/06 12:07:31 [input.harbor_0:2] Feeding stopped: Ffmpeg_decoder.End_of_file.
2023/05/06 12:07:31 [threads:4] Thread "harbor source feeding" terminated (1 remaining).
2023/05/06 12:07:40 [input.harbor_0:4] Buffer emptied, buffering needed.
2023/05/06 12:07:40 [mksafe:3] Switch to safe_blank with transition.
2023/05/06 12:07:55 [blank.strip_0:4] Setting state to blank
2023/05/06 12:07:55 [switch_1:3] Switch to metadata.map_0 with forgetful transition.
2023/05/06 12:07:55 [ZuidWest_FM:2] Error while sending data: could not write data to host: Broken pipe in write()!
2023/05/06 12:07:55 [ogg.muxer:4] ZuidWest_FM: Setting end of track 7bf37a2.
2023/05/06 12:07:55 [ogg.muxer:4] ZuidWest_FM: Every ogg logical tracks have ended: setting end of stream.
2023/05/06 12:07:55 [ZuidWest_FM:3] Closing connection...
2023/05/06 12:07:55 [ZuidWest_FM:3] Will try to reconnect in 3.00 seconds.
2023/05/06 12:07:59 [ZuidWest_FM:3] Connecting mount /zuidwest.stl for source@localhost...
2023/05/06 12:07:59 [ZuidWest_FM:3] Connection setup was successful.
2023/05/06 12:07:59 [ogg.muxer:4] ZuidWest_FM: Starting all streams

Now with:

# Output a high quality ogg/flac stream
output.icecast(%ffmpeg(format="ogg",%audio(codec="flac")),fallible=true,
  host=icecastserver, port=icecastport, password=icecastpassword, mount='/zuidwest.stl', name='ZuidWest FM', description='Studio to Transmitter (uncompressed audio)', radio)

Nothing got disconnected.

2023/05/06 12:15:56 [input.harbor_0:2] Feeding stopped: Ffmpeg_decoder.End_of_file.
2023/05/06 12:15:56 [threads:4] Thread "harbor source feeding" terminated (1 remaining).
2023/05/06 12:16:04 [input.harbor_0:4] Buffer emptied, buffering needed.
2023/05/06 12:16:04 [mksafe:3] Switch to safe_blank with transition.
2023/05/06 12:16:19 [blank.strip_0:4] Setting state to blank
2023/05/06 12:16:19 [switch_1:3] Switch to metadata.map_0 with forgetful transition.

@rmens
Copy link
Author

rmens commented Feb 19, 2024

This issue is popping up again in 2.2.4-1 with my ogg/flac stream when switching from a fallback to a live source via SRT.

Here's my .liq file as reference.

This is in the log

2024/02/19 20:14:14 >>> LOG START
2024/02/19 20:14:09 [ffmpeg.filter.bitstream:3] No valid mode found for filter pgs_frame_merge!
2024/02/19 20:14:09 [main:3] Liquidsoap 2.2.4-1
2024/02/19 20:14:09 [clock:3] Using native (high-precision) implementation for latency control
2024/02/19 20:14:13 [main:3] Standard library loaded in 4.31 seconds.
2024/02/19 20:14:14 [frame:3] Using 44100Hz audio, 25Hz video, 44100Hz main.
2024/02/19 20:14:14 [frame:3] Video frame size set to: 1280x720
2024/02/19 20:14:14 [frame:3] Frame size must be a multiple of 1764 ticks = 1764 audio samples = 1 video samples.
2024/02/19 20:14:14 [frame:3] Targeting 'frame.duration': 0.04s = 1764 audio samples = 1764 ticks.
2024/02/19 20:14:14 [frame:3] Frames last 0.04s = 1764 audio samples = 1 video samples = 1764 ticks.
2024/02/19 20:14:14 [sandbox:3] Sandboxing disabled
2024/02/19 20:14:14 [startup:3] DSSI plugins registration: 0.00s
2024/02/19 20:14:14 [startup:3] FFmpeg filters registration: 0.02s
2024/02/19 20:14:14 [startup:3] FFmpeg bitstream filters registration: 0.00s
2024/02/19 20:14:14 [startup:3] Lilv plugins registration: 0.00s
2024/02/19 20:14:14 [startup:3] Frei0r plugin registration: 0.00s
2024/02/19 20:14:14 [startup:3] LADSPA plugins registration: 0.00s
2024/02/19 20:14:14 [startup:3] Typechecking: 4.11s
2024/02/19 20:14:14 [startup:3] Evaluation: 0.01s
2024/02/19 20:14:14 [startup:3] Typechecking: 0.03s
2024/02/19 20:14:14 [startup:3] Evaluation: 0.00s
2024/02/19 20:14:14 [startup:3] Typechecking: 0.01s
2024/02/19 20:14:14 [startup:3] Evaluation: 0.42s
2024/02/19 20:14:14 [startup:3] Loaded /etc/liquidsoap/radio.liq: 0.42s
2024/02/19 20:14:14 [blank.strip:3] Content type is {audio=pcm(stereo)}.
2024/02/19 20:14:14 [buffer.producer:3] Content type is {audio=pcm(stereo)}.
2024/02/19 20:14:14 [dummy:3] Content type is {audio=pcm(stereo)}.
2024/02/19 20:14:14 [stereotool.2:3] Content type is {audio=pcm(stereo)}.
2024/02/19 20:14:14 [stereotool:3] Content type is {audio=pcm(stereo)}.
2024/02/19 20:14:14 [source:3] Content type is {audio=pcm(stereo)}.
2024/02/19 20:14:14 [single:3] "/var/audio/fallback.ogg" is static, resolving once for all...
2024/02/19 20:14:14 [stereotool:3] Stereotool initialized! Valid license: true, latency: 0.14s, API/software version: 256/10210
2024/02/19 20:14:14 [single:3] Prepared "/var/audio/fallback.ogg" (RID 0).
2024/02/19 20:14:14 [ZuidWest_FM:3] Content type is {audio=pcm(stereo)}.
2024/02/19 20:14:14 [ZuidWest_FM.2:3] Content type is {audio=pcm(stereo)}.
2024/02/19 20:14:14 [ZuidWest_FM.3:3] Content type is {audio=pcm(stereo)}.
2024/02/19 20:14:14 [clock.main:3] Streaming loop starts in auto-sync mode
2024/02/19 20:14:14 [clock.main:3] Delegating synchronization to CPU clock
2024/02/19 20:14:14 [buffer.consumer:3] Content type is {audio=pcm(stereo)}.
2024/02/19 20:14:14 [safe_blank:3] Content type is {audio=pcm(stereo)}.
2024/02/19 20:14:14 [clock.input.srt:3] Streaming loop starts in auto-sync mode
2024/02/19 20:14:14 [clock.input.srt:3] Delegating synchronization to CPU clock
2024/02/19 20:14:14 [video.converter:3] Using preferred video converter: ffmpeg.
2024/02/19 20:14:14 [audio.converter:3] Using samplerate converter: libsamplerate.
2024/02/19 20:14:14 [video.text:3] Using sdl implementation
2024/02/19 20:14:15 [switch.2:3] Switch to source.
2024/02/19 20:14:15 [mksafe:3] Switch to safe_blank.
2024/02/19 20:14:15 [ZuidWest_FM:3] Connecting mount /zuidwest.stl for source@localhost...
2024/02/19 20:14:15 [ZuidWest_FM:3] Connection setup was successful.
2024/02/19 20:14:15 [ZuidWest_FM.2:3] Connecting mount /zuidwest.mp3 for source@localhost...
2024/02/19 20:14:15 [ZuidWest_FM.2:3] Connection setup was successful.
2024/02/19 20:14:15 [ZuidWest_FM.3:3] Connecting mount /zuidwest.aac for source@localhost...
2024/02/19 20:14:15 [ZuidWest_FM.3:3] Connection setup was successful.
2024/02/19 20:14:16 [switch.2:3] Switch to blank.strip with transition.
2024/02/19 20:14:31 [switch.2:3] Switch to source with forgetful transition.
2024/02/19 20:14:31 [ZuidWest_FM:2] Error while sending data: could not write data to host: Unix.Unix_error(Unix.EPIPE, "write", "")!
2024/02/19 20:14:31 [ZuidWest_FM:3] Closing connection...
2024/02/19 20:14:31 [ZuidWest_FM:3] Will try to reconnect in 3.00 seconds.
2024/02/19 20:14:35 [ZuidWest_FM:3] Connecting mount /zuidwest.stl for source@localhost...
2024/02/19 20:14:35 [ZuidWest_FM:3] Connection setup was successful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants