Build on macOS / modern Berkeley DB + FFmpeg 8 - #44
Conversation
Berkeley DB 18 added a 'prefix' parameter to the message callback (now (env, prefix, msg) instead of (env, msg)), which makes the previous db_msg_cb fail to compile against Homebrew's libdb on macOS. Guard with DB_VERSION_MAJOR so the file still builds against older Berkeley DB releases.
build-macos.sh installs the Homebrew dependencies MOC needs, regenerates configure, and runs it with the correct include/lib paths and the CFLAGS workaround required for the AX_PTHREAD probe under clang -Werror. README-MACOS.md documents the three macOS-specific gotchas (FFmpeg 8.x breaks the ffmpeg decoder plugin, AX_PTHREAD trips on -Wextra -Werror, Berkeley DB 18 changed the set_msgcall signature) and the JACK + CoreAudio recipe needed to actually hear audio.
The 2.6-alpha3 source already carried partial FFmpeg-4 fixes (codecpar, avcodec_send_packet/receive_frame migration), but the file still failed to build against FFmpeg 5 and later for two reasons. First, modern <libavformat/avformat.h> no longer transitively defines LIBAVCODEC_VERSION_INT or AVCodecContext, so every version-gated #if in the file silently evaluated as if it were running against ancient libav and pulled in code that uses removed APIs. Including <libavcodec/avcodec.h> explicitly makes the existing guards work and eliminates most of the "undeclared identifier" errors at a stroke. Second, the following APIs were actually removed and need replacing: - channels / channel_layout / request_channel_layout on AVCodecContext (deprecated in 5.1, removed in 7.0). Use the AVChannelLayout struct via a small moc_nb_channels() helper that picks ctx->ch_layout.nb_channels on libavcodec >= 59.24.100 and ctx->channels otherwise. set_downmixing() becomes a no-op on the new API path; mocp's audio_conversion layer handles channel reduction anyway. - AV_CODEC_CAP_TRUNCATED / AV_CODEC_FLAG_TRUNCATED (removed in 5.0). Guarded with LIBAVCODEC_VERSION_INT < 59.0.100. - AVStream.cur_dts became private in 5.x. The previous code used it to decide whether to set AVSEEK_FLAG_BACKWARD; for FFmpeg 5+ we always set it, which gives correct at-or-before semantics for audio in either direction. - avcodec_find_decoder / av_probe_input_format / av_guess_format return const pointers in 5.x. AVCodec / AVInputFormat / AVOutputFormat fields and locals are now declared const. Tested by playing MP3, AAC (m4a), and Opus files through ffmpeg 8.1.1 on macOS; all three decode to JACK with correct duration and sample rate.
The plugin now compiles against the FFmpeg 8.x that Homebrew ships, so drop --without-ffmpeg from the configure invocation and add ffmpeg to the brew install list. Update README-MACOS.md to describe the FFmpeg gotcha as fixed rather than as a "disabled plugin" caveat. With the plugin enabled, the supported codec set expands from flac/vorbis/sndfile/speex to also include mp3, aac, opus, wma, ape, musepack, and the other formats ffmpeg's libavcodec handles.
|
Linking MOC with current versions of BerkDB seems to be illegal due to licence incompatibility. Last year I tried replacing BerkDB with SQLite. Got a working version, but it was rather buggy and I didn't have time to fix it. It can be found in my fork here: https://gitlab.com/tomaszg/mocp/-/tree/sqlite You might also try to check out a version of ffmpeg decoder patches here: https://github.com/xdch47/moc as well as Pulseaudio output driver which might make sense on macOS. There is also a very experimental libao output driver, which can be found in my personal fork: https://gitlab.com/tomaszg/mocp/-/tree/libao (note I didn't keep this particular branch updated in a long time). Anyway, consider posting those thing to the official MOC webpage, instead of a random (probably unmaintained) fork. |
Makes 2.6-alpha3 build against the dependency versions current Linux distros and Homebrew ship today. Tested on macOS 26 / Apple Silicon with BDB 18.1.40 and FFmpeg 8.1.1; all version guards are on
LIBAVCODEC_VERSION_INT/DB_VERSION_MAJOR, so older toolchains keep working.tags_cache.c— BDB 18 added aprefixargument to theset_msgcallcallback.decoder_plugins/ffmpeg/ffmpeg.c— port to FFmpeg 5+ / 8.x. Main finding: modern<libavformat/avformat.h>no longer transitively definesLIBAVCODEC_VERSION_INT, so every existing version guard in the file was silently false and pulled in code using removed APIs. Adding<libavcodec/avcodec.h>+ migrating to theAVChannelLayoutAPI + handling thecur_dts/AV_CODEC_CAP_TRUNCATEDremovals closes https://moc.daper.net/node/3644.build-macos.sh+README-MACOS.md— turn-key macOS build (brew deps, configure flags) and the JACK→CoreAudio recipe needed for audio output.