mikebrady / shairport-sync

AirPlay and AirPlay 2 audio player
Other
7.18k stars 570 forks source link

[Problem]: ffmpeg 7+ crash? #1894

Open acmay opened 1 month ago

acmay commented 1 month ago

What happened?

I tried to start using my Manjaro desktop machine for development and I ran into an issue with the newer ffmpeg version n7.0.1 library and some changed APIs.

This seems to be the deprecated APIs commit but I am not sure how to find the documents on how to handle the change. https://patchwork.ffmpeg.org/project/ffmpeg/patch/20240125134425.374-17-jamrial@gmail.com/#82611

Relevant log output

ffmpeg version n7.0.1 Copyright (c) 2000-2024 the FFmpeg developers
built with gcc 14.1.1 (GCC) 20240522
configuration: --prefix=/usr --disable-debug --disable-static --disable-stripping --enable-amf --enable-avisynth --enable-cuda-llvm --enable-lto --enable-fontconfig --enable-frei0r --enable-gmp --enable-gpl --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libdav1d --enable-libdrm --enable-libdvdnav --enable-libdvdread --enable-libfreetype --enable-libfribidi --enable-libgsm --enable-libharfbuzz --enable-libiec61883 --enable-libjack --enable-libjxl --enable-libmodplug --enable-libmp3lame --enable-libopencore_amrnb --enable-libopencore_amrwb --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libplacebo --enable-libpulse --enable-librav1e --enable-librsvg --enable-librubberband --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libsrt --enable-libssh --enable-libsvtav1 --enable-libtheora --enable-libv4l2 --enable-libvidstab --enable-libvmaf --enable-libvorbis --enable-libvpl --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxcb --enable-libxml2 --enable-libxvid --enable-libzimg --enable-mbedtls --enable-nvdec --enable-nvenc --enable-opencl --enable-opengl --enable-shared --enable-vapoursynth --enable-version3 --enable-vulkan
libavutil      59.  8.100 / 59.  8.100
libavcodec     61.  3.100 / 61.  3.100
libavformat    61.  1.100 / 61.  1.100
libavdevice    61.  1.100 / 61.  1.100
libavfilter    10.  1.100 / 10.  1.100
libswscale      8.  1.100 /  8.  1.100
libswresample   5.  1.100 /  5.  1.100
libpostproc    58.  1.100 / 58.  1.100

=======>> Compile warning
rtp.c: In function ‘avcodec_open2_cleanup_handler’:
rtp.c:2101:3: warning: ‘avcodec_close’ is deprecated [-Wdeprecated-declarations]
 2101 |   avcodec_close(codec_context);
      |   ^~~~~~~~~~~~~
In file included from rtp.c:49:
/usr/include/libavcodec/avcodec.h:2387:5: note: declared here
 2387 | int avcodec_close(AVCodecContext *avctx);
      |     ^~~~~~~~~~~~~

========>> Crash output
         0.000012144 "ptp-utilities.c:165" ptp_shm_interface_open with 2603:8001:5b00:d301:d9f2:17d8:2cac:f724 mapped_addr = 0
         2.255029016 "rtsp.c:2863" Connection 2: SETUP (AirPlay 2)
         0.397469024 "rtsp.c:2863" Connection 3: SETUP (AirPlay 2)
         0.000178742 "rtsp.c:3255" Connection 3: SETUP AP2 no Active-Remote information  the SETUP Record.
         0.000005696 "rtsp.c:3274" Connection 3: SETUP AP2 doesn't include DACP-ID string information.
[SWR @ 0x7f9fbc019540] Input channel layout "" is invalid or unsupported.
[SWR @ 0x7f9fbc019540] Context has not been initialized
[SWR @ 0x7f9fbc019540] Context has not been initialized
Segmentation fault

System Information.

Intel(R) Core(TM) i5-7600K CPU @ 3.80GHz

Configuration Information.

Linux mace 6.6.44-1-MANJARO #1 SMP PREEMPT_DYNAMIC Sat Aug  3 10:09:33 UTC 2024 x86_64 GNU/Linux

PulseAudio or PipeWire installed?

How did you install Shairport Sync?

Built from source

Check previous issues

mikebrady commented 1 month ago

Thanks for the post. What version of Shairport Sync? Are you on the master or the development version?

Could you run:

$ shairport-sync --displayConfig

if possible and post the response please?

acmay commented 1 month ago

It took me a bit to understand SWR prints and the crash was due to ffmpeg. After that I was able to do these error checks to at least output the error from shairplay-sync code and exit rather than crash. I am still looking if I can make some system changes to change ffmpeg to avoid the problem.

diff --git i/rtp.c w/rtp.c
index 41e187e5..cf46d850 100644
--- i/rtp.c
+++ w/rtp.c
@@ -2314,7 +2314,10 @@ void *rtp_buffered_audio_processor(void *arg) {
   // push a deallocator -- av_packet_free(pkt);
   pthread_cleanup_push(swr_alloc_cleanup_handler, &swr);

-  av_opt_set_int(swr, "in_channel_layout", AV_CH_LAYOUT_STEREO, 0);
+  //These seem to be the deprecated APIs
+  int err;
+  err = av_opt_set_int(swr, "in_channel_layout", AV_CH_LAYOUT_STEREO, 0);
+  debug(1, "in_channel layout ret %d", err);
   av_opt_set_int(swr, "out_channel_layout", AV_CH_LAYOUT_STEREO, 0);
   av_opt_set_int(swr, "in_sample_rate", conn->input_rate, 0);
   av_opt_set_int(swr, "out_sample_rate", conn->input_rate,
@@ -2358,7 +2361,11 @@ void *rtp_buffered_audio_processor(void *arg) {
   };

   av_opt_set_sample_fmt(swr, "out_sample_fmt", av_format, 0);
-  swr_init(swr);
+  int swr_ret = swr_init(swr);
+  debug(1, "swr_init failed %d", swr_ret );
+  if (swr_ret != 0){
+    die("swr_init failed");
+  }

   uint8_t packet[16 * 1024];
   unsigned char m[16 * 1024]; // leave the first 7 bytes blank to make room for the ADTS
      0.000006276 "rtsp.c:3274" Connection 1: SETUP AP2 doesn't include DACP-ID string information.
      0.004222061 "rtp.c:2320" in_channel layout ret -1414549496
[SWR @ 0x7f5154016800] Input channel layout "" is invalid or unsupported.
       0.000037660 "rtp.c:2365" swr_init failed -22
       0.000002514 "rtp.c:2367" *fatal error: swr_init failed
       0.000006597 "shairport.c:1734" emergency exit
mikebrady commented 1 month ago

It's important to check with branch off Shairport Sync you are on. Updates have already been made in the development branch which may have already dealt with this issue.

acmay commented 1 month ago

Thanks for the post. What version of Shairport Sync? Are you on the master or the development version?

Could you run:

$ shairport-sync --displayConfig

if possible and post the response please?

It is my unclean development branch. It may take me a few more days before I can try to start fresh again off your code.

acmay commented 1 month ago
         0.001999446 "shairport.c:2131" >> Display Config Start.
         0.001786454 "shairport.c:2131"
         0.000009828 "shairport.c:2131" From "uname -a":
         0.000002232 "shairport.c:2131"  Linux mace 6.6.44-1-MANJARO #1 SMP PREEMPT_DYNAMIC Sat Aug  3 10:09:33 UTC 2024 x86_64 GNU/Linux
         0.002968772 "shairport.c:2131"
         0.000014171 "shairport.c:2131" From /etc/os-release:
         0.000002175 "shairport.c:2131"  Manjaro Linux
         0.002444333 "shairport.c:2131"
         0.000008531 "shairport.c:2131" Shairport Sync Version String:
         0.000002403 "shairport.c:2131"  4.3.4-2-g0b3029ef-dirty-AirPlay2-smi10-OpenSSL-Avahi-ALSA-soxr-sysconfdir:/usr/local/etc
         0.000003445 "shairport.c:2131"
         0.000001596 "shairport.c:2131" Command Line:
         0.000001576 "shairport.c:2131"  ./shairport-sync -v -c desk.conf --displayConfig
         0.000014233 "shairport.c:2131"
         0.000001674 "shairport.c:2131" Configuration File:
         0.000001592 "shairport.c:2131"  /home/acmay/src/airplay/shairport-sync/desk.conf
         0.000001720 "shairport.c:2131"
         0.000023781 "shairport.c:2131" Configuration File Settings:
         0.000002520 "shairport.c:2131"  general :
         0.000001627 "shairport.c:2131"  {
         0.000001487 "shairport.c:2131"    name = "desk";
         0.000001499 "shairport.c:2131"    interface = "enp9s0";
         0.000001729 "shairport.c:2131"    port = 7000;
         0.000001512 "shairport.c:2131"    udp_port_base = 7000;
         0.000001530 "shairport.c:2131"    udp_port_range = 10;
         0.000001517 "shairport.c:2131"    airplay_device_id_offset = 0;
         0.000001876 "shairport.c:2131"    playback_mode = "stereo";
         0.000004543 "shairport.c:2131"  };
         0.000001544 "shairport.c:2131"  alsa :
         0.000001477 "shairport.c:2131"  {
         0.000001482 "shairport.c:2131"    output_device = "plughw:CARD=0";
         0.000001490 "shairport.c:2131"  };
         0.000001474 "shairport.c:2131"
         0.000001371 "shairport.c:2131" >> Display Config End.
         0.000058206 "shairport.c:2280" Startup in AirPlay 2 mode, with features 0x405c4a00,0x1c340 on device "02:76:c6:01:14:52".
         0.000011980 "shairport.c:2319" Version String: "4.3.4-2-g0b3029ef-dirty-AirPlay2-smi10-OpenSSL-Avahi-ALSA-soxr-sysconfdir:/usr/local/etc"
         0.000003286 "shairport.c:2338" Command Line: "./shairport-sync -v -c desk.conf --displayConfig".
         0.000037714 "shairport.c:2374" Log Verbosity is 1.
         0.000008115 "audio_alsa.c:1086" alsa: alsa_maximum_stall_time of 0.200000 sec.
         0.000007612 "audio_alsa.c:1375" alsa: disable_standby_mode is "never".
         0.000001710 "audio_alsa.c:1379" alsa: disable_standby_mode_silence_threshold is 0.040000 seconds.
         0.000001774 "audio_alsa.c:1381" alsa: disable_standby_mode_silence_scan_interval is 0.004000 seconds.
         0.000003212 "audio_alsa.c:1421" alsa: output device name is "plughw:CARD=0".
         0.000030317 "shairport.c:2442" disable_resend_requests is off.
         0.000004156 "shairport.c:2443" diagnostic_drop_packet_fraction is 0.000000. A value of 0.0 means no packets will be dropped deliberately.
         0.000003193 "shairport.c:2447" statistics_requester status is 0.
         0.000001624 "shairport.c:2452" rtsp listening port is 7000.
         0.000001579 "shairport.c:2453" udp base port is 7000.
         0.000001509 "shairport.c:2454" udp port range is 10.
         0.000001542 "shairport.c:2455" player name is "desk".
         0.000001623 "shairport.c:2456" backend is "alsa".
         0.000001484 "shairport.c:2457" run_this_before_play_begins action is "(null)".
         0.000001599 "shairport.c:2458" run_this_after_play_ends action is "(null)".
         0.000001510 "shairport.c:2459" wait-cmd status is 0.
         0.000001539 "shairport.c:2460" run_this_before_play_begins may return output is 0.
         0.000001569 "shairport.c:2461" run_this_if_an_unfixable_error_is_detected action is "(null)".
         0.000001584 "shairport.c:2463" run_this_before_entering_active_state action is  "(null)".
         0.000001531 "shairport.c:2465" run_this_after_exiting_active_state action is  "(null)".
         0.000001547 "shairport.c:2467" active_state_timeout is  10.000000 seconds.
         0.000003816 "shairport.c:2468" mdns backend "(null)".
         0.000003495 "shairport.c:2470" interpolation setting is "auto".
         0.000001606 "shairport.c:2474" interpolation soxr_delay_threshold is 30000000.
         0.000001794 "shairport.c:2475" resync time is 0.050000 seconds.
         0.000001702 "shairport.c:2476" resync recovery time is 0.100000 seconds.
         0.000003337 "shairport.c:2477" allow a session to be interrupted: 0.
         0.000001978 "shairport.c:2478" busy timeout time is 120.
         0.000002473 "shairport.c:2479" drift tolerance is 0.002000 seconds.
         0.000003153 "shairport.c:2480" password is not set.
         0.000003207 "shairport.c:2481" default airplay volume is: -24.000000.
         0.000002701 "shairport.c:2482" high threshold airplay volume is: -16.000000.
         0.000002985 "shairport.c:2484" check for higher-than-threshold volume for new play session is disabled.
         0.000002241 "shairport.c:2490" ignore_volume_control is 0.
         0.000002146 "shairport.c:2494" volume_max_db is not set
         0.000001921 "shairport.c:2495" volume range in dB (zero means use the range specified by the mixer): 0.
         0.000002065 "shairport.c:2497" volume_range_combined_hardware_priority (1 means hardware mixer attenuation is used first) is 0.
         0.000002963 "shairport.c:2501" playback_mode is 0 (0-stereo, 1-mono, 1-reverse_stereo, 2-both_left, 3-both_right).
         0.000002005 "shairport.c:2503" disable_synchronization is 0.
         0.000001996 "shairport.c:2504" use_mmap_if_available is 1.
         0.000001920 "shairport.c:2505" output_format automatic selection is enabled.
         0.000002001 "shairport.c:2509" output_rate automatic selection is enabled.
         0.000001937 "shairport.c:2513" audio backend desired buffer length is 0.200000 seconds.
         0.000002159 "shairport.c:2515" audio_backend_buffer_interpolation_threshold_in_seconds is 0.120000 seconds.
         0.000002234 "shairport.c:2517" audio backend latency offset is 0.000000 seconds.
         0.000002121 "shairport.c:2519" audio backend silence lead-in time is "auto".
         0.000002273 "shairport.c:2523" zeroconf regtype is "_raop._tcp".
         0.000001980 "shairport.c:2524" decoders_supported field is 1.
         0.000002280 "shairport.c:2525" use_apple_decoder is 0.
         0.000001597 "shairport.c:2526" alsa_use_hardware_mute is 0.
         0.000001564 "shairport.c:2528" mdns service interface "enp9s0" requested.
         0.000008062 "shairport.c:2533" configuration file name "desk.conf" resolves to "/home/acmay/src/airplay/shairport-sync/desk.conf".
         0.000003709 "shairport.c:2563" loudness is 0.
         0.000002082 "shairport.c:2564" loudness reference level is -20.000000
         0.000690321 "ptp-utilities.c:165" ptp_shm_interface_open with 0.0.0.0 mapped_addr = 0
         0.000018398 "shairport.c:2691" NQPTP is online.
         0.000130263 "rtsp.c:5492" Here 2
         0.001008644 "mdns_avahi.c:260" avahi:ERROR: selected interface 2
         0.000006353 "mdns_avahi.c:269" Here 2
         1.498777284 "shairport.c:255" "soxr" interpolation has been chosen.
^C        33.672237652 "shairport.c:1731" normal exit
mikebrady commented 1 month ago

It is my unclean development branch. It may take me a few more days before I can try to start fresh again off your code.

Okay, thanks 😊!