Skip to content

Commit da338e3

Browse files
authored
Fix compilation against FFmpeg 3.x (#160)
* Fix compilation of formatcontext.cpp when API_AVFORMAT_URL is undefined * Fix segfault in unit tests by calling av::init() before test execution
1 parent 50cec73 commit da338e3

4 files changed

Lines changed: 19 additions & 5 deletions

File tree

src/formatcontext.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@
99
#include "codeccontext.h"
1010
#include "codecparameters.h"
1111

12+
#if !API_AVFORMAT_URL
13+
extern "C"
14+
{
15+
#include <libavutil/avstring.h>
16+
}
17+
#endif
18+
1219
using namespace std;
1320

1421
namespace {
@@ -60,7 +67,7 @@ void set_uri(AVFormatContext *ctx, string_view uri)
6067
av_free(ctx->url);
6168
ctx->url = av_strdup(uri.data());
6269
#else
63-
av_strlcpy(ctx->filename, uri.data(), std::min<size_t>(sizeof(m_raw->filename), uri.size() + 1));
70+
av_strlcpy(ctx->filename, uri.data(), std::min<size_t>(sizeof(ctx->filename), uri.size() + 1));
6471
ctx->filename[uri.size()] = '\0';
6572
#endif
6673
}

tests/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ enable_testing()
77
#(Catch2 REQUIRED)
88

99
add_library(test_main STATIC test-main.cpp)
10-
target_link_libraries(test_main PUBLIC Catch2::Catch2)
10+
target_link_libraries(test_main PUBLIC Catch2::Catch2 avcpp::avcpp)
1111

1212
add_executable(test_executor
1313
Frame.cpp

tests/meson.build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ catch2 = dependency('catch2', required: true, fallback:['catch2','catch2_dep'])
55
main_test = static_library(
66
'main_test',
77
'test-main.cpp',
8-
dependencies: catch2
8+
dependencies: [catch2, avcpp_dep]
99
)
1010

1111
main_test_dep = declare_dependency(

tests/test-main.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
// In a Catch project with multiple files, dedicate one file to compile the
22
// source code of Catch itself and reuse the resulting object file for linking.
33

4-
// Let Catch provide main():
5-
#define CATCH_CONFIG_MAIN
4+
#define CATCH_CONFIG_RUNNER
65

76
#include <catch2/catch.hpp>
87

8+
#include "av.h"
9+
10+
int main(int argc, char* argv[])
11+
{
12+
av::init();
13+
return Catch::Session().run(argc, argv);
14+
}
15+
916
// That's it
1017

1118
// Compile implementation of Catch for use with files that do contain tests:

0 commit comments

Comments
 (0)