Skip to content

Make avdevice an optional component #144

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads)

find_package(FFmpeg
COMPONENTS AVCODEC AVFORMAT AVUTIL AVDEVICE AVFILTER SWSCALE SWRESAMPLE REQUIRED)
COMPONENTS AVCODEC AVFORMAT AVUTIL AVFILTER SWSCALE SWRESAMPLE REQUIRED OPTIONAL_COMPONENTS AVDEVICE)

add_subdirectory(src)

Expand Down
17 changes: 8 additions & 9 deletions cmake/FindFFmpeg.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -228,16 +228,15 @@ if (NOT TARGET FFmpeg::FFmpeg)
add_library(FFmpeg::FFmpeg ALIAS FFmpeg)
endif()

# Now set the noncached _FOUND vars for the components.
foreach (_component AVCODEC AVDEVICE AVFORMAT AVUTIL POSTPROCESS SWSCALE)
set_component_found(${_component})
endforeach ()

# Compile the list of required vars
set(_FFmpeg_REQUIRED_VARS FFMPEG_LIBRARIES FFMPEG_INCLUDE_DIRS)
set(_FFmpeg_REQUIRED_VARS)
foreach (_component ${FFmpeg_FIND_COMPONENTS})
list(APPEND _FFmpeg_REQUIRED_VARS ${_component}_LIBRARIES ${_component}_INCLUDE_DIRS)
set_component_found(${_component})
# Compile the list of required vars
if (FFmpeg_FIND_REQUIRED_${_component})
list(APPEND _FFmpeg_REQUIRED_VARS ${_component}_LIBRARIES ${_component}_INCLUDE_DIRS)
endif()
endforeach ()

# Give a nice error message if some of the required vars are missing.
find_package_handle_standard_args(FFmpeg DEFAULT_MSG ${_FFmpeg_REQUIRED_VARS})
find_package_handle_standard_args(FFmpeg
REQUIRED_VARS FFMPEG_INCLUDE_DIRS FFMPEG_LIBRARIES ${_FFmpeg_REQUIRED_VARS})
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ foreach(TARGET ${AV_TARGETS})

target_compile_options(${TARGET} PRIVATE ${AVCPP_WARNING_OPTIONS})
target_compile_definitions(${TARGET} PUBLIC __STDC_CONSTANT_MACROS)
target_compile_definitions(${TARGET} PUBLIC AVCPP_HAS_LIBAVDEVICE=${AVDEVICE_FOUND})
target_link_libraries(${TARGET} PRIVATE Threads::Threads PUBLIC FFmpeg::FFmpeg)
target_include_directories(${TARGET}
PUBLIC
Expand Down
3 changes: 3 additions & 0 deletions src/avutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,10 @@ void init()
#if LIBAVFILTER_VERSION_MAJOR < 7 // FFmpeg 4.0
avfilter_register_all();
#endif

#ifdef AVCPP_HAS_LIBAVDEVICE
avdevice_register_all();
#endif

#if LIBAVCODEC_VERSION_MAJOR < 58 // FFmpeg 4.0
av_lockmgr_register(avcpp_lockmgr_cb);
Expand Down
8 changes: 7 additions & 1 deletion src/ffmpeg.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ extern "C"
#include <libavutil/mathematics.h>
#include <libavutil/opt.h>
#include <libavutil/pixdesc.h>
#include <libavdevice/avdevice.h>
#include <libavformat/avformat.h>
#include <libswscale/swscale.h>
#include <libswresample/swresample.h>
#include <libavformat/version.h>
Expand All @@ -30,6 +30,12 @@ extern "C" {
#endif
}

extern "C" {
#ifdef AVCPP_HAS_LIBAVDEVICE
#include <libavdevice/avdevice.h>
#endif
}

// Compat level

// avcodec
Expand Down