From e56c12454690c4cd62afdbf3b67083e6878c832f Mon Sep 17 00:00:00 2001 From: Timothy Lee Date: Mon, 29 Sep 2025 14:10:22 +1000 Subject: [PATCH] Fix compilation against FFmpeg 3.x * Fix compilation of formatcontext.cpp when API_AVFORMAT_URL is undefined * Fix segfault in unit tests by calling av::init() before test execution --- src/formatcontext.cpp | 9 ++++++++- tests/CMakeLists.txt | 2 +- tests/meson.build | 2 +- tests/test-main.cpp | 11 +++++++++-- 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/formatcontext.cpp b/src/formatcontext.cpp index da02a4c8..58baa618 100644 --- a/src/formatcontext.cpp +++ b/src/formatcontext.cpp @@ -9,6 +9,13 @@ #include "codeccontext.h" #include "codecparameters.h" +#if !API_AVFORMAT_URL +extern "C" +{ + #include +} +#endif + using namespace std; namespace { @@ -60,7 +67,7 @@ void set_uri(AVFormatContext *ctx, string_view uri) av_free(ctx->url); ctx->url = av_strdup(uri.data()); #else - av_strlcpy(ctx->filename, uri.data(), std::min(sizeof(m_raw->filename), uri.size() + 1)); + av_strlcpy(ctx->filename, uri.data(), std::min(sizeof(ctx->filename), uri.size() + 1)); ctx->filename[uri.size()] = '\0'; #endif } diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index a5a79348..6cb52235 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -7,7 +7,7 @@ enable_testing() #(Catch2 REQUIRED) add_library(test_main STATIC test-main.cpp) -target_link_libraries(test_main PUBLIC Catch2::Catch2) +target_link_libraries(test_main PUBLIC Catch2::Catch2 avcpp::avcpp) add_executable(test_executor Frame.cpp diff --git a/tests/meson.build b/tests/meson.build index fab07dd8..ff77bf00 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -5,7 +5,7 @@ catch2 = dependency('catch2', required: true, fallback:['catch2','catch2_dep']) main_test = static_library( 'main_test', 'test-main.cpp', - dependencies: catch2 + dependencies: [catch2, avcpp_dep] ) main_test_dep = declare_dependency( diff --git a/tests/test-main.cpp b/tests/test-main.cpp index 492aacfc..64c3d9f1 100644 --- a/tests/test-main.cpp +++ b/tests/test-main.cpp @@ -1,11 +1,18 @@ // In a Catch project with multiple files, dedicate one file to compile the // source code of Catch itself and reuse the resulting object file for linking. -// Let Catch provide main(): -#define CATCH_CONFIG_MAIN +#define CATCH_CONFIG_RUNNER #include +#include "av.h" + +int main(int argc, char* argv[]) +{ + av::init(); + return Catch::Session().run(argc, argv); +} + // That's it // Compile implementation of Catch for use with files that do contain tests: