jakemoroni / audio_async_loopback

Real-time S/PDIF PCM/AC3 capture and playback
GNU General Public License v3.0
25 stars 7 forks source link

Can't build with ffmpeg 5 #6

Open ullebe1 opened 1 year ago

ullebe1 commented 1 year ago

When trying to build on current Arch Linux the build fails since the version of ffmpeg is too new.

The project makes use of avcodec_decode_audio4 which has been removed from ffmpeg 5. This causes builds to fail during linking with:

<artificial>:(.text+0x7a): undefined reference to `avcodec_decode_audio4'

More information can be found in MTG/essentia#1248 where they're having the same issue.

jakemoroni commented 1 year ago

Thanks. Looks like I’ll have to switch to the receive_frame/send_packet API. I should get to it within the week.

jakemoroni commented 1 year ago

This has been fixed in commit c2adb28 and was tested to work with Ubuntu 22.04. However, there were some more warnings for other deprecated functions. Do the changes provided at least fix the issue for Arch?

Tagging @mkkot since I think he was using this for Arch as well (#2)

mkkot commented 1 year ago

I have been using outdated versions, both Arch and audio_async_loopback on my home cinema pc, since I'm too lazy to upgrade and fight with that kind of issues ;)

But I have another PC with Arch and this is the compilation effect on latest and greatest version:

==> Updated version: audio_async_loopback-git r8.c2adb28-1
==> Starting build()...
main.c: In function ‘main’:
main.c:220:5: warning: implicit declaration of function ‘avcodec_register_all’ [-Wimplicit-function-declaration]
  220 |     avcodec_register_all();
      |     ^~~~~~~~~~~~~~~~~~~~
ac3_sink.c: In function ‘ac3_sink_open’:
ac3_sink.c:184:5: warning: ‘av_init_packet’ is deprecated [-Wdeprecated-declarations]
  184 |     av_init_packet(&inst->packet);
      |     ^~~~~~~~~~~~~~
In file included from /usr/include/libavcodec/avcodec.h:45,
                 from ac3_sink.h:27,
                 from ac3_sink.c:30:
/usr/include/libavcodec/packet.h:512:6: note: declared here
  512 | void av_init_packet(AVPacket *pkt);
      |      ^~~~~~~~~~~~~~
ac3_sink.c:189:17: warning: assignment discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
  189 |     inst->codec = avcodec_find_decoder(AV_CODEC_ID_AC3);
      |                 ^
ac3_sink.c: In function ‘ac3_sink_process’:
ac3_sink.c:333:5: warning: ‘channels’ is deprecated [-Wdeprecated-declarations]
  333 |     if (inst->frame->channels != 6) {
      |     ^~
In file included from /usr/include/libavcodec/avcodec.h:35:
/usr/include/libavutil/frame.h:643:9: note: declared here
  643 |     int channels;
      |         ^~~~~~~~
ac3_sink.c:339:9: warning: ‘channels’ is deprecated [-Wdeprecated-declarations]
  339 |         printf("Only 5.1 is supported right now (channels = %d)\n", inst->frame->channels);
      |         ^~~~~~
/usr/include/libavutil/frame.h:643:9: note: declared here
  643 |     int channels;
      |         ^~~~~~~~
/usr/bin/ld: /tmp/ccizSkHt.ltrans0.ltrans.o: in function `main':
<artificial>:(.text.startup+0x36): undefined reference to `avcodec_register_all'
collect2: error: ld returned 1 exit status
ffmpeg -v
ffmpeg version n5.1.2 Copyright (c) 2000-2022 the FFmpeg developers
  built with gcc 12.2.0 (GCC)
  configuration: --prefix=/usr --disable-debug --disable-static --disable-stripping --enable-amf --enable-avisynth --enable-cuda-llvm --enable-lto --enable-fontconfig --enable-gmp --enable-gnutls --enable-gpl --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libdav1d --enable-libdrm --enable-libfreetype --enable-libfribidi --enable-libgsm --enable-libiec61883 --enable-libjack --enable-libmfx --enable-libmodplug --enable-libmp3lame --enable-libopencore_amrnb --enable-libopencore_amrwb --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-librav1e --enable-librsvg --enable-libsoxr --enable-libspeex --enable-libsrt --enable-libssh --enable-libsvtav1 --enable-libtheora --enable-libv4l2 --enable-libvidstab --enable-libvmaf --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxcb --enable-libxml2 --enable-libxvid --enable-libzimg --enable-nvdec --enable-nvenc --enable-opencl --enable-opengl --enable-shared --enable-version3 --enable-vulkan
  libavutil      57. 28.100 / 57. 28.100
  libavcodec     59. 37.100 / 59. 37.100
  libavformat    59. 27.100 / 59. 27.100
  libavdevice    59.  7.100 / 59.  7.100
  libavfilter     8. 44.100 /  8. 44.100
  libswscale      6.  7.100 /  6.  7.100
  libswresample   4.  7.100 /  4.  7.100
  libpostproc    56.  6.100 / 56.  6.100

There is also ffmpeg4.4 package available in official repos, but it requires different path:

/usr/include/ffmpeg4.4/
/usr/include/ffmpeg4.4/libavcodec/

I guess that we want version 5 support anyway, so I will refrain from patching my package for now.

ullebe1 commented 1 year ago

Hi @jakemoroni, thank you for looking into it so quickly!

I can echo what @mkkot wrote above, I get the same result with the newest main.

mkkot commented 1 year ago

@ullebe1 I created a PR: https://github.com/jakemoroni/audio_async_loopback/pull/8 Is it possible for you to test?

jakemoroni commented 1 year ago

Hey @mkkot,

I've accepted your pull request and have also made some more small fixes in commit d7af319.

Hopefully this fixes the build issues. There's still a deprecation warning for the channels field in the AVFrame structure, but I'm only using that field for a sanity check, so I could remove it if it becomes an issue.

mkkot commented 1 year ago

Hey @jakemoroni , thanks for keeping this program alive. If I ever start learning C, I will blame audio-async-loopback.

Since Archlinux doesn't have a live CD, I finally found Ubuntu Mantic Minotaur and used mantic-desktop-amd64.iso 2023-05-18 06:23 with ffmpeg 5.1.3, linux 6.2.0 and my Creative ZxR. After fruitless struggling with build-in sound control I installed pavucontrol, switched sound configuration, enabled muted outputs in alsamixer and confirmed it works. No need for changes in config.h or adding any arguments to program call. Tested with HBO max. No sound cracking, no visible delay.

mkkot commented 1 year ago

AUR package was updated and I can confirm it compiles and runs under Archlinux. Although I think that AUR packages just take the latest master. But at least the metadata is refreshed.

jakemoroni commented 1 year ago

Thanks @mkkot

I appreciate your help here and I'm glad you find the program to be useful. I just fixed another somewhat critical bug today, btw.

Also, it's interesting that you found that this works on Ubuntu Mantic Minotaur since I would assume that uses Pipewire instead of Pulseaudio. That's good to know.

mkkot commented 1 year ago

Pipewire is there, but pulseaudio is there as well. When I run alsamixer, I see pipewire output first. Not sure how this is configured, maybe pulseaudio is just another sound source to pipewire? TBH I noticed pipewire name but didn't care too much as it just worked.