8000 Fix: Resolve C library compilation errors in source_avcodec.c by joshsc63 · Pull Request #429 · aubio/aubio · GitHub
[go: up one dir, main page]

Skip to content

Fix: Resolve C library compilation errors in source_avcodec.c - #429

Closed
joshsc63 wants to merge 1 commit into
aubio:masterfrom
joshsc63:fix-c-library-bugs
Closed

joshsc63 wants to merge 1 commit into
aubio:masterfrom
joshsc63:fix-c-library-bugs

Conversation

@joshsc63
Copy link
Copy Markdown

Fix: Resolve C Library Compilation Errors in source_avcodec.c

This PR fixes two critical compilation issues in the C library that cause build failures on modern systems.

Issues Fixed

1. Address Comparison Bug (Line 625)

Error:

error: the comparison will always evaluate as 'true' for the address of 'avFormatCtx'
will never be NULL [-Werror=address]
  625 |   if (s && &(s->avFormatCtx) != NULL) {

Root Cause: Taking the address of a struct member (&(s->avFormatCtx)) always produces a non-NULL value, making the comparison meaningless and triggering a compiler error with -Werror.

Fix: Remove the & operator to check the pointer value itself:

if (s && s->avFormatCtx != NULL) {

Impact: Resolves compilation failure on Linux and Linux_double builds.


2. FFmpeg 7.0+ Compatibility (Lines 68-71)

Error:

error: use of undeclared identifier 'AV_INPUT_BUFFER_MIN_SIZE'
   70 | #define AUBIO_AVCODEC_MAX_BUFFER_SIZE AV_INPUT_BUFFER_MIN_SIZE

Root Cause: AV_INPUT_BUFFER_MIN_SIZE was removed in FFmpeg 7.0 (LIBAVUTIL version 57.28.100).

Fix: Add version-specific handling with a fallback value:

#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(56, 56, 0)
#define AUBIO_AVCODEC_MAX_BUFFER_SIZE FF_MIN_BUFFER_SIZE
#elif LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(57, 28, 100)
// FFmpeg 7.0+ removed AV_INPUT_BUFFER_MIN_SIZE, use fallback
#define AUBIO_AVCODEC_MAX_BUFFER_SIZE 16384
#else
#define AUBIO_AVCODEC_MAX_BUFFER_SIZE AV_INPUT_BUFFER_MIN_SIZE
#endif

Fallback Value: 16384 bytes (16KB) is a safe default that:

  • Matches the typical value of AV_INPUT_BUFFER_MIN_SIZE in FFmpeg < 7
  • Provides sufficient buffer space for audio decoding
  • Is widely used across multimedia applications

Impact: Resolves compilation failure on macOS builds with FFmpeg 8.0+.


Changes

File Modified: src/io/source_avcodec.c

  • Line 625: Fixed address comparison logic
  • Lines 68-71: Added FFmpeg 7.0+ compatibility

Total Changes:

  • +4 lines added (FFmpeg version check and fallback)
  • -1 line modified (address comparison fix)

Compatibility

Backward Compatible: ✅ Yes

  • FFmpeg < 7.0: Uses existing AV_INPUT_BUFFER_MIN_SIZE
  • FFmpeg >= 7.0: Uses new fallback value
  • All platforms: Address comparison now works correctly

Testing:

  • ✅ Compiles with FFmpeg 6.x and earlier
  • ✅ Compiles with FFmpeg 7.0+
  • ✅ Compiles with FFmpeg 8.0+
  • ✅ Address comparison logic validated

Relationship to Other PRs

This PR is separate from PR #428 (NumPy/Python extension fix). While investigating CI failures for #428, I discovered these C library bugs were blocking the build. This PR fixes the C library issues, allowing #428's Python extension fix to be properly validated.

PR #428: Fixes Python extension compilation with NumPy 1.19+ and GCC 14
This PR: Fixes C library compilation with modern FFmpeg versions


Checklist

  • Fixes compile-time errors
  • No runtime behavior changes
  • Backward compatible
  • Version-gated for safety
  • Follows existing code patterns
  • No breaking changes

Status: Ready for review and merge
Risk Level: Low (compile-time fixes only)
Impact: High (unblocks builds on modern systems)

Fixes two critical compilation issues:

1. Address comparison bug (line 625)
   - Error: comparing address of struct member instead of pointer value
   - Fix: Remove & operator from &(s->avFormatCtx) comparison
   - Impact: Resolves -Werror=address compilation failure

2. FFmpeg 7.0+ compatibility (lines 68-71)
   - Error: AV_INPUT_BUFFER_MIN_SIZE undefined in FFmpeg 7+
   - Fix: Add version check for LIBAVUTIL >= 57.28.100 with fallback value
   - Impact: Resolves compilation on systems with FFmpeg 7.0 or newer

These are separate bugs from the NumPy/Python extension fix in PR aubio#428.
Both bugs affect the C library (libaubio) compilation with -Werror flag.

Tested environments:
- Linux with FFmpeg < 7.0 (existing AV_INPUT_BUFFER_MIN_SIZE path)
- Linux with FFmpeg >= 7.0 (new fallback path)
- All platforms (address comparison fix)
@joshsc63
Copy link
Copy Markdown
Author

Closing this PR as the fix has been consolidated into PR #428.

PR #428 now includes:

See PR #428 for the complete consolidated fix with all contributor credits.

@joshsc63 joshsc63 closed this Oct 28, 2025
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 this pull request may close these issues.

1 participant

0